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


当前回答

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

window.location === document.location

其他回答

文档。location最初是一个只读属性,尽管Gecko浏览器也允许你为它赋值。为了跨浏览器安全,请使用window。位置相反。

阅读更多:

document.location

window.location

至少在IE中,它在本地文件上有一点不同:

文档。URL将返回 ”文件:/ / C: \ \ abc \ a.html项目”

但是window。location。href会返回 “文件:/ / / C: / / abc / a.html”项目

一个是反斜杠,一个是正斜杠。

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

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

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

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

also

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

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

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

window.location === document.location