Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.location vs. document.location [duplicate]

Should both of them reference the same object?

like image 934
Morgan Cheng Avatar asked Mar 12 '10 06:03

Morgan Cheng


People also ask

What is the difference between window location and 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).

When should I use Windows location replacement?

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.

What is the difference between window location and location href?

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.

What does window location mean?

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.


1 Answers

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

like image 120
rahul Avatar answered Sep 20 '22 00:09

rahul