JS 中document.URL 和 windows.location.href 的区别
2009-11-11 20:09
841 查看
document 表示的是一个文档对象,windows 表示一个窗口对象。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 //www.jb51.net/#server
打印 alert(document.URL ); 和 alert(windows.location.href);
发现,这两个的值不一样,
document.URL : //www.jb51.net/
windows.location.href ://www.jb51.net/#server
所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 //www.jb51.net/#server
打印 alert(document.URL ); 和 alert(windows.location.href);
发现,这两个的值不一样,
document.URL : //www.jb51.net/
windows.location.href ://www.jb51.net/#server
所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。
您可能感兴趣的文章:
相关文章推荐
- JS 中document.URL 和 windows.location.href 的区别
- JS 中document.URL 和 windows.location.href 的区别
- JS 中document.URL 和 windows.location.href 的区别
- JS 中document.URL 和 windows.location.href 的区别
- JS 中document.URL 和 windows.location.href 的区别
- JS 中document.URL 和 window.location.href 的区别
- JS document.URL , windows.location.href 的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- 几种location.href的区别 js实现网页防止被iframe框架嵌套功能
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别
- 详解location.href几种用法的区别【JS跳转】
- js实现页面跳转,location.href和location.replace和location.reload的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- 几种location.href的区别 js实现网页防止被iframe框架嵌套功能 .
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- js实现网页防止被iframe框架嵌套及几种location.href的区别
- 几种location.href的区别 js实现网页防止被iframe框架嵌套功能
- js实现网页防止被iframe框架嵌套及几种location.href的区别