扫码关注官方订阅号
window.location 和 window.document.location 有什么本质性的区别吗?
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
没有区别, 都是location对象的引用 window.location == document.location
javascriptwindow.location === document.location; // true
javascript
window.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
W3C 规范: http://www.w3.org/TR/2011/WD-html5-20110525/history.html#the-location-...
规范里面真的说这俩货冒得区别。
jswindow.location === window.document.location // true
js
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. 明显,两者是相等的
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
没有区别, 都是location对象的引用
window.location == document.location
根据 W3C 规范:
window 的 location 属性指的就是 window 对象的 document 属性的 location,二者是一回事。所以:
W3C 规范: http://www.w3.org/TR/2011/WD-html5-20110525/history.html#the-location-...
规范里面真的说这俩货冒得区别。
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.
明显,两者是相等的