coderef

LocationBaseline · Widely available

The location global object represents the current page's address. You can use it to get the parts of the address (such as location.hostname or location.pathname) or navigate to another URL.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.

Browser support

DesktopChrome
1+Supportedsince Dec 11, 2008
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1+Supportedsince Nov 9, 2004
Current: 157
Safari
1+Supportedsince Jun 23, 2003
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157
Safari iOS
1+Supportedsince Jun 29, 2007
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: location.

Feature detection

JS · check before using
if ("Location" in globalThis) {
  // Location is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (17). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Document.location112141843.2
Location112111841
Location.ancestorOrigins20791486251486
Location.assign112131841
Location.hash112111841
Location.host112111841
Location.hostname112111841
Location.href112111841
Location.origin812215.118215
Location.pathname112111841
Location.port112111841
Location.protocol112111841
Location.reload112111841
Location.replace112111841
Location.search112111841
Location.toString521222152221
Window.location112111841