Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between window.location and document.location in JavaScript?

Should both of them reference the same object?

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

Morgan Cheng


People also ask

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

What is document window and location JavaScript?

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. location object can be accessed without window.

What is document location in JavaScript?

The Document. location read-only property returns a Location object, which contains information about the URL of the document and provides methods for changing that URL and loading another URL. Though Document. location is a read-only Location object, you can also assign a string to it.


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 132
rahul Avatar answered Oct 22 '22 06:10

rahul