--- title: URL.origin slug: Web/API/URL/origin translation_of: Web/API/URL/origin ---
{{APIRef("URL API")}}
URL
.origin
是一个只读属性,返回一个 {{domxref("USVString")}} 类型值,包含 URL 源经过 Unicode 序列化之后的值, 也就是:
http
或者 https
协议的 URL, 返回协议名, 然后是 '://'
, 然后是域, 然后是 ':'
, 最后是端口号 (默认端口是 80
和 443
);file:
协议的 URL, 返回值因浏览器而异;blob:
协议的 URL, 返回值是 blob:
后跟随的源地址. 例如 "blob:https://mozilla.org"
将会返回 "https://mozilla.org".
{{AvailableInWorkers}}
string = URLObject.origin;
var result = new URL("blob:https://mozilla.org:443/").origin; // 返回:'https://developer.mozilla.org:443'
规范 | ?状态 | 备注 |
---|---|---|
{{SpecName('URL', '#dom-url-origin', 'URL.origin')}} | {{Spec2('URL')}} | Initial definition. |
{{ CompatibilityTable() }}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatChrome(52)}} | {{CompatNo}} [1] | {{CompatGeckoDesktop("26.0")}} [2][3] | {{CompatNo}} [1] | {{CompatNo}} [1] | {{CompatNo}} [1] |
Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | {{CompatChrome(52)}} | {{CompatChrome(52)}} | {{CompatNo}} [1] | {{CompatGeckoMobile("26.0")}} [2][3] | {{CompatNo}} [1] | {{CompatNo}} [1] | {{CompatNo}} [1] |
[1] Though not grouped in a single abstract interface, this method is directly available on the interfaces that implement it, if this interface is supported.
[2] From Gecko 26 to Gecko 44, this property was on the URLUtils
mixin. It has been moves either on the HTMLHyperlinkElementUtils
mixin, or directly on the interface.
[3] Before Gecko 49, results for URL using the blob
scheme incorrectly returned null
.