--- title: WindowOrWorkerGlobalScope.origin slug: Web/API/origin tags: - global scope - origin - serialized translation_of: Web/API/WindowOrWorkerGlobalScope/origin original_slug: Web/API/WindowOrWorkerGlobalScope/origin ---
{{APIRef()}}{{SeeCompatTable}}{{domxref("WindowOrWorkerGlobalScope")}} 接口的 origin
只读属性返回全局范围的 origin, 序列化为一个字符串。
let myOrigin = self.origin; // or just origin
A {{domxref("USVString")}}.
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"
.
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'webappapis.html#dom-origin', 'WindowOrWorkerGlobalScope.origin')}} | {{Spec2('HTML WHATWG')}} | Initial definition. |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatChrome(59)}} | {{CompatGeckoDesktop(54)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatChrome(59)}} | {{CompatChrome(59)}} | {{CompatGeckoMobile(54)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |