--- title: Location slug: Web/API/Location tags: - API - HTML DOM - Interface - Location - NeedsTranslation - Reference - TopicStub translation_of: Web/API/Location ---
{{APIRef("HTML DOM")}}
The Location interface represents the location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both the {{domxref("Document")}} and {{domxref("Window")}} interface have such a linked Location, accessible via {{domxref("Document.location")}} and {{domxref("Window.location")}} respectively.
The Location interface doesn't inherit any property, but implements those from {{domxref("URLUtils")}}.
':'.':', and the port of the URL.'/' followed by the path of the URL.'?' followed by the parameters or "querystring" of the URL. Modern browsers provide URLSearchParams and URL.searchParams to make it easy to parse out the parameters from the querystring.'#' followed by the fragment identifier of the URL.The Location interface doesn't inherit any method, but implements those from {{domxref("URLUtils")}}.
true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.assign() method is that after using replace() the current page will not be saved in session {{domxref("History")}}, meaning the user won't be able to use the back button to navigate to it.// Create anchor element and use href property for the purpose of this example
// A more correct alternative is to browse to the URL and use document.location or window.location
var url = document.createElement('a');
url.href = 'https://developer.mozilla.org:8080/en-US/search?q=URL#search-results-close-container';
console.log(url.href); // https://developer.mozilla.org:8080/en-US/search?q=URL#search-results-close-container
console.log(url.protocol); // https:
console.log(url.host); // developer.mozilla.org:8080
console.log(url.hostname); // developer.mozilla.org
console.log(url.port); // 8080
console.log(url.pathname); // /en-US/search
console.log(url.search); // ?q=URL
console.log(url.hash); // #search-results-close-container
console.log(url.origin); // https://developer.mozilla.org
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG', "browsers.html#the-location-interface", "Location")}} | {{Spec2('HTML WHATWG')}} | No change from {{SpecName("HTML5 W3C")}}. |
| {{SpecName('HTML5 W3C', "browsers.html#the-location-interface", "Location")}} | {{Spec2('HTML5 W3C')}} | Initial definition. |
{{Compat("api.Location")}}