手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS 中document.URL 和 windows.location.href 的区别
JS 中document.URL 和 windows.location.href 的区别
摘要:document表示的是一个文档对象,windows表示一个窗口对象。一个窗口下面可以有很多的document对象。每个document都有...

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 的区别】相关文章:

javascript检测两个数组是否相似

JSON与XML优缺点对比分析

实例剖析AngularJS框架中数据的双向绑定运用

让焦点自动跳转

JavaScript中的toUTCString()方法使用详解

基于JavaScript实现智能右键菜单

Javascript中setTimeOut和setInterval的定时器用法

深入浅析JavaScript面向对象和原型函数

JavaScript中Number.MIN_VALUE属性的使用示例

javascript实现youku的视频代码自适应宽度

精品推荐
分类导航