javascript - 关于一个location对象的问题
高洛峰
高洛峰 2017-04-10 15:35:34
[JavaScript讨论组]

window.location 和 window.document.location 有什么本质性的区别吗?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(5)
ringa_lee

没有区别, 都是location对象的引用
window.location == document.location

迷茫
javascriptwindow.location === document.location;    // true
怪我咯

根据 W3C 规范:

The location attribute of the Window interface must return the Location object for that Window object's Document.

window 的 location 属性指的就是 window 对象的 document 属性的 location,二者是一回事。所以:

window.location === window.document.location   // true
PHPz

W3C 规范: http://www.w3.org/TR/2011/WD-html5-20110525/history.html#the-location-...

规范里面真的说这俩货冒得区别。

jswindow.location === window.document.location   // true
大家讲道理

The Location interface

Each Document object in a browsing context's session history is associated with a unique instance of a Location object.

document . location [ = value ]
window . location [ = value ]
Returns a Location object with the current page's location.

Can be set, to navigate to another page.
明显,两者是相等的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号