--- title: URL slug: Web/API/URL tags: - API - Experimental - Expérimental(2) - NeedsTranslation - TopicStub - URL API translation_of: Web/API/URL ---
{{ApiRef("URL API")}} {{SeeCompatTable}}

La interfaz URL representa a un objeto que provee métodos estáticos para crear objetos URL.

When using a user agent where no constructor has been implemented yet, it is possible to access such an object using the {{domxref("Window.URL")}} properties (prefixed with Webkit-based browser as Window.webkitURL).

{{AvailableInWorkers}}

Properties

{{domxref("URL.href")}}
Is a {{domxref("DOMString")}} containing the whole URL.
{{domxref("URL.protocol")}}
Is a {{domxref("DOMString")}} containing the protocol scheme of the URL, including the final ':'.
{{domxref("URL.host")}}
Is a {{domxref("DOMString")}} containing the host, that is the hostname, a ':', and the port of the URL.
{{domxref("URL.hostname")}}
Is a {{domxref("DOMString")}} containing the domain of the URL.
{{domxref("URL.port")}}
Is a {{domxref("DOMString")}} containing the port number of the URL.
{{domxref("URL.pathname")}}
Is a {{domxref("DOMString")}} containing an initial '/' followed by the path of the URL.
{{domxref("URL.search")}}
Is a {{domxref("DOMString")}} containing a '?' followed by the parameters of the URL.
{{domxref("URL.hash")}}
Is a {{domxref("DOMString")}} containing a '#' followed by the fragment identifier of the URL.
{{domxref("URL.username")}}
Is a {{domxref("DOMString")}} containing the username specified before the domain name.
{{domxref("URL.password")}}
Is a {{domxref("DOMString")}} containing the password specified before the domain name.
{{domxref("URL.origin")}} {{readonlyInline}}
Returns a {{domxref("DOMString")}} containing the origin of the URL, that is its scheme, its domain and its port.
{{domxref("URL.searchParams")}}
Returns a {{domxref("URLSearchParams")}} object allowing to access the GET query arguments contained in the URL.

Constructor

{{domxref("URL.URL", "URL()")}}
Creates and return a URL object composed from the given parameters.

Methods

The URL interface implements methods defined in {{domxref("URLUtils")}}.

{{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.

Static methods

{{domxref("URL.createObjectURL()")}}
Returns a {{domxref("DOMString")}} containing a unique blob URL, that is a URL with blob: as its scheme, followed by an opaque string uniquely identifying the object in the browser.
{{domxref("URL.revokeObjectURL()")}}
Revokes an object URL previously created using {{domxref("URL.createObjectURL()")}}.

Specifications

Specification Status Comment
{{SpecName('File API', '#creating-revoking', 'URL')}} {{Spec2('File API')}} Added the static methods URL.createObjectURL() and URL.revokeObjectURL().
{{SpecName('URL', '#api', 'Node')}} {{Spec2('URL')}} Initial definition (implements URLUtils).

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 8.0[2]
32
In Development[5] {{CompatGeckoDesktop("2.0")}}[1][3]
{{CompatGeckoDesktop("19.0")}}
{{CompatNo}}[4] 15.0[2]
19
6.0[2]
7.0
username, password, and origin 32 {{CompatUnknown}} {{CompatGeckoDesktop("26.0")}} {{CompatUnknown}} 19 {{CompatVersionUnknown}}
searchParams {{CompatChrome(49)}} {{CompatUnknown}} {{CompatGeckoDesktop("29.0")}} {{CompatUnknown}} 36 {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 4[2]
4.4
8.0[2]
32
{{CompatGeckoMobile("14.0")}}[1][3]
{{CompatGeckoMobile("19.0")}}
{{CompatVersionUnknown}} 15.0[2] 6.0[2]
username, password, and origin 4.4 32 {{CompatGeckoDesktop("26.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatVersionUnknown}}
searchParams {{CompatNo}} {{CompatChrome(49)}} {{CompatGeckoMobile("29.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] From Gecko 2 (Firefox 4) to Gecko 18 included, Gecko supported this interface with the non-standard nsIDOMMozURLProperty internal type. As the only to access such an object was through {{domxref("window.URL")}}, in practice, this didn't make any difference.

[2] This feature is implemented under the non-standard name webkitURL.

[3] For Firefox, to use from chrome code, JSM and Bootstrap scope, you have to import it like this:

Cu.importGlobalProperties(['URL']);

URL is available in Worker scopes.

[4] As of IE11, instantiating new URL objects is not supported - ie. new URL() does not work. 

[5] Edge in development: see https://developer.microsoft.com/en-us/microsoft-edge/platform/status/urlapi/  and https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/6263638-url-api

See also