Document.domain

Document インターフェイスの domain プロパティは、同一オリジンポリシーで使用される現在の文書のオリジンのうち、ドメインの部分を取得または設定します。

このプロパティが正常に設定されると、オリジンのポート番号の部分も null に設定されます。

構文

const domainString = document.domain
document.domain = domainString

現在の文書のオリジンのうち、ドメインの部分です。

例外

SecurityError

以下の状況のうちの一つで、 domain を設定することが試みられた。

ドメイン名の取得

http://developer.mozilla.org/ja/docs/Web の URI において、この例は currentDomain に "developer.mozilla.org" の文字列を設定します。

js
const currentDomain = document.domain;

ウィンドウを閉じる

文書が www.example.xxx/good.html のような "www.example.xxx" のドメインを持つ場合、この例はウィンドウを閉じようとします。

js
const badDomain = "www.example.xxx";

if (document.domain === badDomain) {
  // 単なる例: window.close() は効果がないことがある
  window.close();
}

仕様書

Specification
HTML Standard
# relaxing-the-same-origin-restriction

ブラウザーの互換性

BCD tables only load in the browser

関連情報