aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/document/domain/index.html
blob: 47d2a70db74ec9fa8c25c3dac02f4914ed8636be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
title: Document.domain
slug: Web/API/Document/domain
tags:
  - API
  - Document
  - Domain
  - HTML DOM
  - Property
  - Same Origin
  - Same Origin Policy
  - iframe
translation_of: Web/API/Document/domain
---
<div>{{ApiRef}}</div>

<div>Свойство <code>domain</code> у {{domxref("Document")}} интерфейса получает/устанавливает доменную часть источника происхождения (origin) текущего документа, используется в <a href="https://developer.mozilla.org/en-US/docs/Same_origin_policy_for_JavaScript" title="Same origin policy for JavaScript">политике ограничения домена (same origin policy)</a>.</div>

<h2 id="Summary" name="Summary">Синтаксис</h2>

<pre class="syntaxbox">var <var>domainString</var> = document.domain;
document.domain = <var>string</var>;</pre>

<h3 id="Значение">Значение</h3>

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

<h3 id="Исключения">Исключения</h3>

<dl>
 <dt><code>SecurityError</code></dt>
 <dd>An attempt has been made to set <code>domain</code> under one of the following conditions:
 <ul>
  <li>The document is inside a sandboxed {{htmlelement("iframe")}}</li>
  <li>The document has no browsing context</li>
  <li>The document's <a href="https://html.spec.whatwg.org/multipage/origin.html#concept-origin-effective-domain">effective domain</a> is <code>null</code></li>
  <li>The given value is not equal to the document's effective domain (or it is not a registerable domain suffix of it)</li>
  <li>The {{httpheader('Feature-Policy/document-domain','document-domain')}} {{HTTPHeader("Feature-Policy")}} is enabled</li>
 </ul>
 </dd>
</dl>

<h2 id="Examples">Examples</h2>

<h3 id="Getting_the_domain">Getting the domain</h3>

<p>For the URI <code>http://developer.mozilla.org/en-US/docs/Web</code>, this example sets <code>currentDomain</code> to the string "<code>developer.mozilla.org</code>".</p>

<pre><code>var currentDomain = document.domain;</code></pre>

<h3 id="Closing_a_window">Closing a window</h3>

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

<pre><code>var badDomain = "www.example.xxx";

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

<h2 id="Notes" name="Notes">Замечания</h2>

<p>Свойство возвращает <code>null</code> если домен документа не может быть идентифицирован, хотя теперь это изменилось с Firefox 62 - смотри обсуждение в {{bug(819475)}}.</p>

<p>Mozilla позволит вам установить его в супердомен текущего значения, ограниченный его  <a href="/en-US/docs/XPCOM_Interface_Reference/nsIEffectiveTLDService#getBaseDomain.28.29">базовым доменом</a>. Например, на developer.mozilla.org возможно установить его как "mozilla.org" но не как  "mozilla.com" или "org".</p>

<p>Если это свойство успешно установлено, портовая часть источника так же устанавливается на нуль.</p>

<p>Mozilla отличает свойство <code>document.domain</code>, которое никогда не было установлено от явно установленного такого же домена как в URL документа, хотя свойство возвращает одинаковое значение в обоих случаях. Один документ разрешает доступ к другому, если они оба установили <code>document.domain</code> в одинаковое значение, указывая тем самым на их намерение сотрудничать или ни один из них не установил <code>document.domain</code>, а домены в URL-адресах одинаковые (<a class="link-https" href="https://mxr.mozilla.org/mozilla-central/source/caps/nsPrincipal.cpp?rev=ecb7068b07a1&amp;mark=199-215#199" title="https://mxr.mozilla.org/mozilla-central/source/caps/src/nsScriptSecurityManager.cpp#1003">реализация</a>). Если бы не эта специальная политика, то каждый сайт будет подвержен XSS от своих поддоменов (для примера <a class="link-https" href="https://bugzilla.mozilla.org" rel="freelink">https://bugzilla.mozilla.org</a> может быть атакован с помощью заведения багов (bug attachments) на <a class="link-https" href="https://bug*.bugzilla.mozilla.org" rel="freelink">https://bug*.bugzilla.mozilla.org</a>).</p>

<h2 id="Specification" name="Specification">Спецификации</h2>

<table>
 <thead>
  <tr>
   <th scope="col"><strong>Спецификация</strong></th>
   <th scope="col"><strong>Статус</strong></th>
   <th scope="col"><strong>Комментарий</strong></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG','origin.html#relaxing-the-same-origin-restriction','Document.domain')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('HTML 5.2','browsers.html#relaxing-the-same-origin-restriction','Document.domain')}}</td>
   <td>{{Spec2('HTML 5.2')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2>

<div class="hidden">Таблица совместимости на этой странице генерируется из структурированных данных. Если вы желаете внести свой вклад в данные, пожалуйста ознакомьтесь с <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a>  и отправьте нам pull request.</div>

<p>{{Compat("api.Document.domain")}}</p>

<h2 id="See_also" name="See_also">Смотрите также</h2>

<ul>
 <li><a href="/en-US/docs/Same_origin_policy_for_JavaScript" title="Same origin policy for JavaScript">Политика ограничения домена для JavaScriptHTML</a></li>
</ul>