AwaitedDOM/ Location

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 Document and Window interface have such a linked Location, accessible via Document.location and Window.location respectively.

Properties

.hash
W3C

Is a string containing a '#' followed by the fragment identifier of the URL.

Type: Promise<string>

.host
W3C

Is a string containing the host, that is the hostname, a ':', and the port of the URL.

Type: Promise<string>

.hostname
W3C

Is a string containing the domain of the URL.

Type: Promise<string>

.href
W3C

Is a stringifier that returns a string containing the entire URL. If changed, the associated document navigates to the new page. It can be set from a different origin than the associated document.

Type: Promise<string>

.origin
W3C

Returns a string containing the canonical form of the origin of the specific location.

Type: Promise<string>

.pathname
W3C

Is a string containing an initial '/' followed by the path of the URL.

Type: Promise<string>

.port
W3C

Is a string containing the port number of the URL.

Type: Promise<string>

.protocol
W3C

Is a string containing the protocol scheme of the URL, including the final ':'.

Type: Promise<string>

Is a string containing a '?' 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.

Type: Promise<string>

Methods

.assign(url)
W3C

Loads the resource at the URL provided in parameter.

Arguments:

  • url string. Is a string containing the URL of the page to navigate to.

Returns: Promise<void>

.reload()
W3C

Reloads the resource from the current URL. Its optional unique parameter is a boolean, which, when it is 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.

Returns: Promise<void>

.replace(url)
W3C

Replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History, meaning the user won't be able to use the back button to navigate to it.

Arguments:

  • url string. Is a string containing the URL of the page to navigate to.

Returns: Promise<void>

.toString()
W3C

Returns a string containing the whole URL. It is a synonym for HTMLHyperlinkElementUtils.href, though it can't be used to modify the value.

Returns: Promise<string>

Edit this page on GitHub