aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/document/domain/index.html
blob: 35bed661f73988a202617fe1945e11f91fc9cbfe (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
---
title: Document.domain
slug: Web/API/Document/domain
tags:
  - API
  - Document
  - HTML DOM
  - Property
  - Reference
translation_of: Web/API/Document/domain
---
<div>{{ApiRef}}</div>

<p>{{domxref("Document")}} 인터페이스의 <strong><code>domain</code></strong> 속성은 <a href="/ko/docs/Web/Security/Same-origin_policy">동일 출처 정책</a>에서 사용하는 현재 문서의 {{glossary("origin", "출처")}}에서 도메인 부분을 설정하거나 가져옵니다.</p>

<p><code>domain</code> 속성을 성공적으로 설정하면 출처의 포트를 {{jsxref("null")}}로 설정합니다.</p>

<h2 id="구문">구문</h2>

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

<h3 id="값"></h3>

<p>현재 문서 출처의 도메인 부분.</p>

<h3 id="예외">예외</h3>

<dl>
 <dt><code>SecurityError</code></dt>
 <dd>다음 상황에서 <code>domain</code>을 변경하려 시도한 경우.
 <ul>
  <li>샌드박스 설정된 {{htmlelement("iframe")}} 요소에 속한 문서</li>
  <li>{{glossary("browsing context", "브라우징 맥락")}}이 없는 문서</li>
  <li>문서의 <a href="https://html.spec.whatwg.org/multipage/origin.html#concept-origin-effective-domain">유효 도메인</a><code>null</code></li>
  <li>주어진 값이 문서의 유효 도메인과 같지 않거나, 등록 가능한 도메인 접미사가 아닌 경우</li>
  <li>{{httpheader('Feature-Policy/document-domain','document-domain')}} {{HTTPHeader("Feature-Policy")}} 헤더가 설정된 경우</li>
 </ul>
 </dd>
</dl>

<h2 id="예제">예제</h2>

<h3 id="도메인_가져오기">도메인 가져오기</h3>

<p><code>http://developer.mozilla.org/en-US/docs/Web</code> 주소에서, 다음 코드는 <code>currentDomain</code> 변수에 "<code>developer.mozilla.org</code>"  문자열을 할당합니다.</p>

<pre class="brush:js">const currentDomain = document.domain;</pre>

<h3 id="창_닫기">창 닫기</h3>

<p>어느 문서, 예컨대 <code>www.example.xxx/good.html</code> 등이 <code>www.example.com</code>의 도메인을 가지고 있을 때, 다음 예제는 창을 닫으려 시도합니다.</p>

<pre class="brush:js">const badDomain = "www.example.xxx";

if (document.domain == badDomain) {
  // 예시에 불과 (window.close()는 아무것도 하지 않을 수도 있음)
  window.close();
}
</pre>

<h2 id="명세">명세</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</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>
 </tbody>
</table>

<h2 id="브라우저_호환성">브라우저 호환성</h2>



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

<h2 id="같이_보기">같이 보기</h2>

<ul>
 <li><a href="/ko/docs/Web/Security/Same-origin_policy">동일 출처 정책</a></li>
</ul>