Document.domain

Устарело: Эта возможность была удалена из веб-стандартов. Хотя некоторые браузеры по-прежнему могут поддерживать её, она находится в процессе удаления. Не используйте её ни в старых, ни в новых проектах. Страницы или веб-приложения, использующие её, могут в любой момент сломаться.

Свойство domain у Document интерфейса получает/устанавливает доменную часть источника происхождения (origin) текущего документа, используется в политике ограничения домена (same origin policy).

Синтаксис

var domainString = document.domain;
document.domain = string;

Значение

Доменная часть источника происхождения (origin) текущего документа.

Исключения

SecurityError

An attempt has been made to set domain under one of the following conditions:

  • The document is inside a sandboxed <iframe>
  • The document has no browsing context
  • The document's effective domain is null
  • The given value is not equal to the document's effective domain (or it is not a registerable domain suffix of it)
  • The document-domain Feature-Policy is enabled

Examples

Getting the domain

For the URI http://developer.mozilla.org/ru/docs/Web, this example sets currentDomain to the string "developer.mozilla.org".

var currentDomain = document.domain;

Closing a window

If a document, such as www.example.xxx/good.html, has the domain of "www.example.xxx", this example attempts to close the window.

var badDomain = "www.example.xxx";

if (document.domain == badDomain) {
  // Just an example: window.close() sometimes has no effect
  window.close();
}

Спецификации

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

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
domain
Deprecated

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Deprecated. Not for use in new websites.
See implementation notes.
Has more compatibility info.

Смотрите также