--- title: URL.origin slug: Web/API/URL/origin translation_of: Web/API/URL/origin ---

{{APIRef("URL API")}}

URL.origin 是一个只读属性,返回一个 {{domxref("USVString")}} 类型值,包含 URL 源经过 Unicode 序列化之后的值, 也就是:

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

See also