{{APIRef("URLUtils")}}
The Location
interface represents the location 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.
Properties
The Location
interface doesn't inherit any property, but implements those from {{domxref("URLUtils")}}.
- {{domxref("URLUtils.href")}}
- Is a {{domxref("DOMString")}} containing the whole URL.
- {{domxref("URLUtils.protocol")}}
-
Is a {{domxref("DOMString")}} containing the protocol scheme of the URL, including the final
':'
. - {{domxref("URLUtils.host")}}
-
Is a {{domxref("DOMString")}} containing the host, that is the hostname, a
':'
, and the port of the URL. - {{domxref("URLUtils.hostname")}}
- Is a {{domxref("DOMString")}} containing the domain of the URL.
- {{domxref("URLUtils.port")}}
- Is a {{domxref("DOMString")}} containing the port number of the URL.
- {{domxref("URLUtils.pathname")}}
-
Is a {{domxref("DOMString")}} containing an initial
'/'
followed by the path of the URL. - {{domxref("URLUtils.search")}}
-
Is a {{domxref("DOMString")}} containing a
'?'
followed by the parameters of the URL. - {{domxref("URLUtils.hash")}}
-
Is a {{domxref("DOMString")}} containing a
'#'
followed by the fragment identifier of the URL. - {{domxref("URLUtils.username")}}
- Is a {{domxref("DOMString")}} containing the username specified before the domain name.
- {{domxref("URLUtils.password")}}
- Is a {{domxref("DOMString")}} containing the password specified before the domain name.
- {{domxref("URLUtils.origin")}} {{readOnlyInline}}
- Returns a {{domxref("DOMString")}} containing the canonical form of the origin of the specific location.
Methods
The Location
interface doesn't inherit any method, but implements those from {{domxref("URLUtils")}}.
- {{domxref("Location.assign()")}}
- Loads the resource at the URL provided in parameter.
- {{domxref("Location.reload()")}}
-
Reloads the resource from the current URL. Its optional unique parameter is a {{domxref("Boolean")}}, which, when it is
true
, causes the page to always be reloaded from the server. If it isfalse
or not specified, the browser may reload the page from its cache. - {{domxref("Location.replace()")}}
-
Replaces the current resource with the one at the provided URL. The difference from the
assign()
method is that after usingreplace()
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. - {{domxref("URLUtils.toString()")}}
- Returns a {{domxref("DOMString")}} containing the whole URL. It is a synonym for {{domxref("URLUtils.href")}}, though it can't be used to modify the value.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "history.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. |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
origin on Windows.location |
{{CompatUnknown}} | {{CompatGeckoDesktop("21")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
origin on all location objects (but on Workers, that use {{domxref("WorkerLocation")}} |
{{CompatUnknown}} | {{CompatGeckoDesktop("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
username and password |
{{CompatUnknown}} | {{CompatGeckoDesktop("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
origin on Windows.location |
{{CompatUnknown}} | {{CompatGeckoMobile("21")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
origin on all location objects (but on Workers, that use {{domxref("WorkerLocation")}}) |
{{CompatUnknown}} | {{CompatGeckoMobile("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
username and password |
{{CompatUnknown}} | {{CompatGeckoMobile("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
See also
- Two methods creating such an object: {{domxref("Window.location")}} and {{domxref("Document.location")}}.