--- title: Document.origin slug: Web/API/Document/origin translation_of: Web/API/Document/origin ---
{{APIRef("DOM")}}{{SeeCompatTable}}

Document.origin (只读属性) 返回文档的来源。通常该属性与 document.defaultView.location.origin 相等。

示例

var origin = document.origin;
// On this page, returns:'https://developer.mozilla.org'

var origin = document.origin;
// On "about:blank", returns:'null'

var origin = document.origin;
// On "data:text/html,<b>foo</b>", returns:'null'

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#dom-document-origin', 'Document.origin')}} {{Spec2('DOM WHATWG')}} Initial definition.
{{SpecName('HTML WHATWG', '#origin:document', 'origin for Document objects')}} {{Spec2('HTML WHATWG')}} Initial definition.

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatChrome(41)}} {{CompatNo}} {{bug(931884)}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

参见