Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The read-only location property of the Window interface returns a Location object with information about the current location of the document.
See Location for all available properties.
A Location object.
Although the location property itself is read-only in the sense that you can't replace the Location object, you can still assign to the location property directly, which is equivalent to assigning to its href property. You can also modify the Location object using the assign() and replace() methods.
Whenever a new value is assigned to the location object, a document will be loaded using the URL as if location.assign() had been called with the modified URL.
Note that navigation-related sandbox flags may result in an exception being thrown and the navigation failing.
Consider the following example, which will reload the page by using the replace() method to insert the value of location.pathname into the hash:
The current URL with "?Some%20data" appended is sent to the server (if no action is taken by the server, the current document is reloaded with the modified search string).
…the same thing but with an animated page scroll:
| HTML # the-location-interface |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Nov 25, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.