--- title: URLUtils slug: Web/API/HTMLHyperlinkElementUtils translation_of: Web/API/HTMLHyperlinkElementUtils original_slug: Web/API/URLUtils ---

{{ApiRef("URL API")}}{{SeeCompatTable}}

The URLUtils interface defines utility methods to work with URLs.

There are no objects of this type, but several objects implement it, such as {{domxref("Location")}}, {{domxref("URL")}}, {{domxref("HTMLAnchorElement")}}, and {{domxref("HTMLAreaElement")}}.

Properties

This interface doesn't inherit any property.

{{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, and then, if the port of the URL is not empty (which can happen because it was not specified or because it was specified to be the default port of the URL's scheme), 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 origin of the URL, that is its scheme, its domain and its port.
{{domxref("URLUtils.searchParams")}}
Returns a {{domxref("URLSearchParams")}} object allowing to access the GET query arguments contained in the URL.

Methods

This interface doesn't inherit any method.

{{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('URL', '#urlutils', 'URLUtils')}} {{Spec2('URL')}} Initial definition

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}} [1] {{CompatGeckoDesktop("22")}} [1] {{CompatNo}} [1] {{CompatNo}} [1] {{CompatNo}} [1]
searchParams {{CompatUnknown}} {{CompatGeckoDesktop("29")}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}
username and password {{CompatUnknown}} {{CompatGeckoDesktop("26")}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}
origin {{CompatUnknown}} {{CompatGeckoDesktop("26")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
origin on Windows.location {{CompatUnknown}} {{CompatGeckoDesktop("21")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} [1] {{CompatNo}} [1] {{CompatGeckoMobile("22")}} [1] {{CompatNo}} [1] {{CompatNo}} [1] {{CompatNo}} [1]
searchParams {{CompatUnknown}} {{CompatUnknown}} {{CompatNo}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}
username and password {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("26")}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}
origin {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("26")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
origin on Windows.location {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile("21")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Though not grouped in a single abstract interface, these methods are directly available on the interfaces that implement it, if this interface is supported.

See also