URL:origin 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
备注: 此特性在 Web Worker 中可用。
URL
接口的 origin
只读属性返回一个包含所表示 URL 的来源(origin)的 Unicode 序列化形式的字符串。
具体结构因 URL 类型而异:
- 对于
http
或https
URL,其格式为:协议名紧接'://'
,随后是域名,紧接着是':'
,之后是端口号(如果明确指定且非默认端口——分别为80
和443
)。 - 对于
file:
URL,其值取决于浏览器。 - 对于
blob:
URL,将使用blob:
后面的 URL 的来源。例如,"blob:https://mozilla.org"
将返回"https://mozilla.org"
。
值
字符串
示例
js
const url = new URL("blob:https://mozilla.org:443/");
console.log(url.origin); // 输出“https://mozilla.org”
const url = new URL("http://localhost:80/");
console.log(url.origin); // 输出“http://localhost”
const url = new URL("https://mozilla.org:8080/");
console.log(url.origin); // 输出“https://mozilla.org:8080”
规范
Specification |
---|
URL # dom-url-origin |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
origin |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
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.
参见
URL
接口