origin

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

WindowOrWorkerGlobalScope 接口的 origin 只读属性返回全局范围的 origin, 序列化为一个字符串。

Syntax

let myOrigin = self.origin; // or just origin

Value

Examples

Executed from inside a worker script, the following snippet will log the worker's global scope's origin to the console each time it receives a message

onmessage = function() {
  console.log(self.origin);
};

If the origin is not a scheme/host/port tuple (say you are trying to run it locally, i.e. via file:// URL), origin will return the string "null".

Specifications

Specification
HTML Standard
# dom-origin-dev

Browser compatibility

BCD tables only load in the browser