MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

翻譯不完整。請協助 翻譯此英文文件

這是一個實驗中的功能
此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。

URL 介面提供了建立 URL 物件的靜態方法。

使用尚未實作此物件的瀏覽器時,可以改用 Window.URL 屬性來呼叫(基於 Webkit 或 Blink 引擎的瀏覽器可使用 Window.webkitURL)。

註: This feature is available in Web Workers.

屬性

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

建構式

URL()
Creates and return a URL object composed from the given parameters.

方法

The URL interface implements methods defined in URLUtils.

URLUtils.toString()
Returns a DOMString containing the whole URL. It is a synonym for URLUtils.href, though it can't be used to modify the value.

靜態方法

URL.createObjectURL()
Returns a 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.
URL.revokeObjectURL()
Revokes an object URL previously created using URL.createObjectURL().

規範

Specification Status Comment
File API
The definition of 'URL' in that specification.
Working Draft Added the static methods URL.createObjectURL() and URL.revokeObjectURL().
URL
The definition of 'Node' in that specification.
Living Standard Initial definition (implements URLUtils).

瀏覽器相容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 8.0[2]
32
? 4.0 (2.0)[1][3]
19.0 (19.0)
10.0 15.0[2]
19
6.0[2]
7.0
username, password, and origin 32 ? 26.0 (26.0) ? 19 (Yes)
searchParams 49 ? 29.0 (29.0) ? 36 No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 4[2]
4.4
8.0[2]
32
14.0 (14.0)[1][3]
19.0 (19.0)
(Yes) 15.0[2] 6.0[2]
username, password, and origin 4.4 32 26.0 (26.0) ? ? (Yes)
searchParams No support 49 29.0 (29.0) ? ? ?

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

參見

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo, Sebastianz
 最近更新: jackblackevo,