码迷,mamicode.com
首页 > Windows程序 > 详细

JS 中document.URL 和 windows.location.href 的区别

时间:2014-12-20 13:02:26      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

实际上,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.jb51.net/
windows.location.href :http://www.jb51.net/#server
所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。

JS 中document.URL 和 windows.location.href 的区别

标签:

原文地址:http://my.oschina.net/guomingliang/blog/358309

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!