DOM Window.location Property
The location property gives information about the current URL and lets you navigate to another page.
Description
The location property returns a Location object describing the current URL, with parts such as href, protocol, host, pathname, search and hash. Assigning to location.href (or location) navigates to a new page; location.replace() does so without adding a history entry, and location.reload() reloads.
To read query parameters, combine it with URLSearchParams: new URLSearchParams(location.search).get('q').
Changing location.hash scrolls to the matching element without reloading the page and adds a history entry, and the hashchange event reports it. For single-page applications that change the URL without reloading, use history.pushState() instead of setting location.
Syntax
location
location.href = urlValue
A Location object with the current URL's parts and methods to navigate.
Example
Browser Support
The following information will show you the current browser support for the Window.location property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





