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" 是 ...
随机推荐
- 540C: Ice Cave
题目链接 题意: n*m的地图,'X'表示有裂痕的冰块,'.'表示完整的冰块,有裂痕的冰块再被踩一次就会碎掉,完整的冰块被踩一次会变成有裂痕的冰块, 现在告诉起点和终点,问从起点能否走到终点并且使终点 ...
- JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-003映射实体时的可选操作(<delimited-identifiers/>、PhysicalNamingStrategy、PhysicalNamingStrategyStandardImpl、、、)
一.自定义映射的表名 1. @Entity @Table(name = "USERS") public class User implements Serializable { / ...
- MakeObjectInstance的前世今生(关键是ECX的何时入栈以及Self指针何时存储的)
高手们的文章有很大启发,但是总有些小错,也有没交代清楚的,以下是我的理解: 编译器编译MainWndProc的时候,它是一个正常Delphi普通函数,MakeObjectInstance对它做变换是运 ...
- Linux系统PATH变量配置
alias命令用于设置命令的别名,格式为“alias 别名=命令” 例如担心复制文件时误将文件被覆盖,可以执行alias cp=" cp -i",如此一来 每次复制命令都会询问用户 ...
- Xlib: connection to ":0.0" refused by server Xlib: No protocol specified解决方案
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified 解决办法: 1. 退出oracl ...
- wamp集成环境开启虚拟主机多站点功能
方法/步骤 如果不是全白色,说明没有正常启动,先解决这个情况再进行下一步操作. 我们一键安装wamp到D盘,并可以正常启动,状态如下图所示: 在D:\wamp\bin\apache\Apach ...
- 日期工具类 - DateUtil.java
日期工具类,提供对日期的格式化和转换方法.获取区间日期.指定日期.每月最后一天等. 源码如下:(点击下载 -DateUtil.java.commons-lang-2.6.jar ) import ja ...
- HttpClient通过GET和POST获取网页内容
中国银行支付网关---银行回调的接口 最简单的HTTP客户端,用来演示通过GET或者POST方式访问某个页面 /** * 中国银行支付网关---银行回调的接口 * @svncode svn://10. ...
- 无开发经验,初学python
1.无开发经验,初学python 如果你不会其他语言,python是你的第一门语言: A Byte of Python (简明python教程,这个有中文版简明 Python 教程)是非常好的入门 ...
- Oracle —— 表结构相关的SQL
1.表基本信息(Table) select * from user_tables t, user_tab_comments c where c.table_name = t.table_name an ...