Document: location property

Baseline Widely available

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 Document interface returns a Location object, which contains information about the URL of the document and provides methods for changing that URL and loading another URL.

To retrieve just the URL as a string, the read-only document.URL property can also be used.

Value

A Location object. If the current document is not in a browsing context, the returned value is null.

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.

Examples

js
console.log(document.location);
// Prints a Location object to the console

Specifications

Specification
HTML
# the-location-interface

Browser compatibility

See also