origin 只读特性在 URL interface returns a USVString containing the Unicode serialization of the origin of the represented URL. The exact structure varies depending on the type of URL:

  • For http or https URLs, the scheme followed by '://' , followed by the domain, followed by ':' , followed by the port (the default port, 80 and 443 respectively, if explicitly specified).
  • For 文件: URLs, the value is browser dependant.
  • for blob: URLs, the origin of the URL following blob: will be used, e.g "blob:https://mozilla.org" will be returned as "https://mozilla.org".
注意: 此特征可用于 Web 工作者 .

句法

const originString = url.origin
						

A USVString .

范例

const url = new URL("blob:https://mozilla.org:443/")
console.log(url.origin); // Logs 'https://mozilla.org'
						

规范

规范 状态 注释
URL
The definition of 'URL.origin' in that specification.
实时标准 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
origin Chrome 32 Edge 12 Firefox 26
26
不支持 26 — 49
Results for URL 使用 blob scheme incorrectly returned null .
IE No Opera Yes Safari 10 WebView Android ≤37 Chrome Android 32 Firefox Android 26
26
不支持 26 — 49
Results for URL 使用 blob scheme incorrectly returned null .
Opera Android Yes Safari iOS Yes Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. URL API
  2. URL
  3. 构造函数
    1. URL()
  4. 特性
    1. hash
    2. host
    3. hostname
    4. href
    5. origin
    6. password
    7. pathname
    8. port
    9. 协议
    10. search
    11. searchParams
    12. username
  5. 方法
    1. createObjectURL()
    2. revokeObjectURL()
    3. toJSON()
    4. toString()
  6. Related pages for URL API
    1. HTMLHyperlinkElementUtils
    2. URLSearchParams
    3. URLUtilsReadOnly

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1