窗口之间有什么区别。Location和document。Location ?它们是否都引用同一个对象?
当前回答
文档。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
窗口。考虑到较老的浏览器,位置是两者中更可靠的一致性。
是的,它们是一样的。这是浏览器JS API的众多历史怪癖之一。试着做:
window.location === document.location
文档。location最初是一个只读属性,尽管Gecko浏览器也允许你为它赋值。为了跨浏览器安全,请使用window。位置相反。
阅读更多:
document.location
window.location
Document.location.constructor === window.location.constructor为true。
这是因为它与document.location===window.location中看到的对象完全相同。
因此,不需要比较构造函数或任何其他属性。