Should both of them reference the same object?
Actually I notice a difference in chrome between both , For example if you want to do a navigation to a sandboxed frame from a child frame then you can do this just with document.location but not with window.location
document.location.constructor === window.location.constructor
is true
.
It's because it's exactly the same object as you can see from document.location===window.location
.
So there's no need to compare the constructor or any other property.
According to the W3C, they are the same. In reality, for cross browser safety, you should use window.location
rather than document.location
.
See: http://www.w3.org/TR/html/browsers.html#dom-location
Well yea, they are the same, but....!
window.location
is not working on some Internet Explorer browsers.
Yes, they are the same. It's one of the many historical quirks in the browser JS API. Try doing:
window.location === document.location
window.location is read/write on all compliant browsers.
document.location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).