Should both of them reference the same object?
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).
location adds an item to your history in that you can (or should be able to) click "Back" and go back to the current page. window. location. replace replaces the current history item so you can't go back to it.
window. location is an object that holds all the information about the current document location (host, href, port, protocol etc.). location. href is shorthand for window.
The location property of a window (i.e. window. location ) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With