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-onlylocation property of theDocument interface returns aLocation 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-onlydocument.URLproperty can also be used.
In this article
Value
ALocation object. If the current document is not in a browsing context, the returned value isnull.
Although thelocation property itself is read-only in the sense that you can't replace theLocation object, you can still assign to thelocation property directly, which is equivalent to assigning to itshref property. You can also modify theLocation object using theassign() andreplace() methods.
Examples
console.log(document.location);// Prints a Location object to the consoleSpecifications
| Specification |
|---|
| HTML> # the-location-interface> |
Browser compatibility
See also
- The interface of the returned value,
Location - A similar information, but attached to thebrowsing context,
Window.location