Favorites

DOM Window.location Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.location
DOM Window PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

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 = url

Value

A Location object with the current URL's parts and methods to navigate.

Example

console.log(location.href);
console.log(location.protocol, location.pathname);
const params = new URLSearchParams('?q=grid&page=2');
console.log(params.get('q'), params.get('page'));

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.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee