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

  • 对于使用 http 或者 https 协议的 URL, 返回协议名, 然后是 '://', 然后是域, 然后是 ':', 最后是端口号 (默认端口是 80 和 443);
  • 对于使用 file: 协议的 URL, 返回值因浏览器而异;
  • 对于使用 blob: 协议的 URL, 返回值是 blob: 后跟随的源地址. 例如 "blob:https://mozilla.org" 将会返回 "https://mozilla.org".
Note: 此特性在 Web Worker 中可用。


string = URLObject.origin;


var result = new URL("blob:https://mozilla.org:443/").origin;
// 返回:'https://developer.mozilla.org:443'


规范 ?状态 备注
Living Standard Initial definition.


We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 52 未实现 [1] 26.0 (26.0) [2][3] 未实现 [1] 未实现 [1] 未实现 [1]
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 52 52 未实现 [1] 26.0 (26.0) [2][3] 未实现 [1] 未实现 [1] 未实现 [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