窗口之间有什么区别。Location和document。Location ?它们是否都引用同一个对象?


当前回答

实际上,我注意到两者之间的chrome的区别,例如,如果你想做一个导航到沙盒框架从一个子框架,那么你可以这样做,只是与文档。Location,但不是window。Location

其他回答

是的,它们是一样的。这是浏览器JS API的众多历史怪癖之一。试着做:

window.location === document.location

是的,他们是一样的,但是....!

窗口。location在某些Internet Explorer浏览器上无法工作。

文档。Location ===窗口。Location返回true

also

Document.location.constructor === window.location.constructor为true

注:仅在Firefox 3.6、Opera 10和IE6上测试

根据W3C的说法,它们是相同的。实际上,为了跨浏览器的安全性,您应该使用window。Location而不是document.location。

见:http://www.w3.org/TR/html/browsers.html dom-location

Document.location.constructor === window.location.constructor为true。

这是因为它与document.location===window.location中看到的对象完全相同。

因此,不需要比较构造函数或任何其他属性。