window.location 和 window.document.location 有什么本质性的区别吗?
没有区别, 都是location对象的引用
window.location == document.location
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-...
规范里面真的说这俩货冒得区别。
js
window.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.
明显,两者是相等的