JS 中document.URL 和 window.location.href 的区别
实际上,document 和 window 这两个对象的区别已经包含了这个问题的答案。
document 表示的是一个文档对象,window 表示一个窗口对象。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 http://yourhost.com/#fragment
打印 alert(document.URL ); 和 alert(window.location.href);
发现,这两个的值不一样,
document.URL 的值是 “http://yourhost.com/”
window.location.href 的值是 “http://yourhost.com/#fragment”
差一个 #fragment
所以,如果要用 fragment 进行相应的处理的话,最好是用 window.location.href
否则会出现很奇怪的错误。
另:以下是屏蔽页面使用查看源码和复制拷贝页面内容的js代码
document.oncontextmenu=function(e){return false;}
document.onmousedown = function() {
return false;
};
document.onselectstart = function() {
return false;
};
JS 中document.URL 和 window.location.href 的区别的更多相关文章
- JS 中document.URL 和 windows.location.href 的区别
实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,windows 表示一个窗口对象. 一个窗口下面可以有很多的docu ...
- document.URL vs window.location.href All In One
document.URL vs window.location.href All In One document.URL 与 window.location.href 两者有啥区别 document. ...
- document.URL 和 windows.location.href的区别
1. 从输出结果上,document.URL 和 windows.location.href 没有区别.2. 非要说区别的话,你只可以读取document.URL的值,不能修改它.windows.lo ...
- JS中document对象和window对象有什么区别
简单来说,document是window的一个对象属性.Window 对象表示浏览器中打开的窗口.如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 windo ...
- JS中 window.location 与window.location.href的区别
疑惑:window.location='url' 与window.lcoation.href='url'效果一样,都会跳转到新页面,区别在哪?查得的资料如下: 1:window.location是页 ...
- 【JavaScript】获取当前页的URL与window.location.href
原文:http://blog.csdn.net/yongh701/article/details/45688743 版权声明:本文为博主原创文章,未经博主允许欢迎乱转载,标好作者就可以了!感谢欣赏!觉 ...
- 页面的URL分析----window.location.href
window.location是页面的位置对象window.location.href是 location的一个属性值,并且它是location的默认属性. window.location直接赋值一个 ...
- javascript中window.open()与window.location.href的区别
window.open("www.baidu.com"); 只是表示打开这个页面,并不是打开并刷新baidu.com window.location.href="www. ...
- window.top.location.href 和 window.location.href 的区别
"window.location.href"."location.href"是本页面跳转. "parent.location.href" 是 ...
随机推荐
- lintcode:组成最大的数
最大数 给出一组非负整数,重新排列他们的顺序把他们组成一个最大的整数. 注意事项 最后的结果可能很大,所以我们返回一个字符串来代替这个整数. 样例 给出 [1, 20, 23, 4, 8],返回组合最 ...
- OpenStack学习系列-----第一篇 OpenStack介绍
刚开始接触OpenStack,被它所承诺的前景,以及现在业界对它的期望吸引(OpenStack被誉为21世纪的Linux开源社区,可以预见其的发展前景是何其广阔.).怎么说呢,我现在也暂时相信,Ope ...
- 对话框上右下角显示resize icon(可以拖动改变对话框的大小)(在WM_CREATE的时候,增加WS_THICKFRAME风格)
CStatusBar m_StatusBar; // 成员变量 // 全局变量 static UINT auIDStatusBar[] = { ID_SEPARATOR }; //在对话框类的WM_ ...
- 302. Smallest Rectangle Enclosing Black Pixels
题目: An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The b ...
- android调试工具DDMS
DDMS工作机制 DDMS全称Dalvik Debug Monitor Service.DDMS为IDE和emultor及真正的android设备架起来了一座桥梁,Android DDMS将捕捉 ...
- Android 使用意图传递数据
使用意图传递数据之通用方式. 测试应用:当前页面点击button传递数据到一个新的页面显示在textview中. 首先在,mainActivity.xml文件中加入一个button按钮 <But ...
- Effective C++条款01: 视C++为一个语言联邦
一开始C++定义为:C with Classes. 如今的C++已经是一个多重范型编程语言,可以把C++视为有四个次语言组成的联邦语言. C.C++任然以C为基础.区块.语句.预处理.内置语言类型.数 ...
- css 射线实现方法
一个斜的四边形 .top_ad_out::before { content: ''; position: absolute; z-index: -1; width: 336px; height: 25 ...
- c# 文件简繁体转换
C# 文件简繁体转换 简繁体转换: 方案一: 准确性高,耗性能 方案二: 准确性低,效率高 1 using Microsoft.International.Converters.Tradition ...
- linux 配置 wlan 连接
第一步,先确定你已经安装了无线网卡驱动.我的是 ath9k ,linux 内核不自带,现编译成模块 然后安装上.具体步骤请自行搜索 linux 编译内核 第二步,起用模块 modprobe ath9k ...