JS 中document.URL 和 windows.location.href 的区别
来源:互联网 发布:java中abstract的作用 编辑:程序博客网 时间:2024/05/14 15:13
实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案。
document 表示的是一个文档对象,windows 表示一个窗口对象。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 http://www.jb51.net/#server
打印 alert(document.URL ); 和 alert(windows.location.href);
发现,这两个的值不一样,
document.URL : http://www.xxx.net/
windows.location.href :http://www.xxx.net/#server
所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 http://www.jb51.net/#server
打印 alert(document.URL ); 和 alert(windows.location.href);
发现,这两个的值不一样,
document.URL : http://www.xxx.net/
windows.location.href :http://www.xxx.net/#server
所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。
转载地址:http://www.jb51.net/article/20872.htm
0 0
- JS 中document.URL 和 windows.location.href 的区别
- JS 中document.URL 和 windows.location.href 的区别
- JS document.URL , windows.location.href 的区别
- document.location.href 和window.location.href的区别
- Document.location.href和.replace的区别
- Document.location.href和.replace的区别
- Document.location.href和.replace的区别
- location.href="#"与document.url ="#"的区别
- location.href="#",document.URL="#"与document.url="#"的区别
- location和location.href跳转url的区别
- location和location.href跳转url的区别
- location和location.href跳转url的区别
- location和location.href跳转url的区别
- location和location.href跳转url的区别
- document.location.reload和document.location.href的比较
- javascript中window.location和window.location.href的区别
- js中的 window.location、document.location、document.URL 对像的区别
- js中的 window.location、document.location、document.URL 对像的区别
- AppStore 1.0.24 版本被拒原因分析
- 【多线程】博客
- sonar Java规范
- 错误:手动SQL语句拼接时,注意空格
- 【HDU5739 2016 Multi-University Training Contest 2F】【cdq分治+并查集做法 or 点双连通做法】Fantasia 每点删除后联通块权值和的积
- JS 中document.URL 和 windows.location.href 的区别
- CentOS下安装tar包/rpm包
- Spring4笔记----bean的作用范围
- Android 琐碎note (always update)
- [HDU 5754] Life Winner Bo (有平局的博弈+威佐夫博弈)
- java中判断字符串是否为数字的方法的几种方法
- iOS调试技巧(转载)
- Java技巧--修改Eclipse默认Workspace路径
- HDU 1874 (迪杰斯特拉 + 邻接表 + 优先队列 模板)