--- title: Document.domain slug: Web/API/Document/domain tags: - API - Document - HTML DOM - Property - Reference translation_of: Web/API/Document/domain ---
{{domxref("Document")}} 인터페이스의 domain 속성은 동일 출처 정책에서 사용하는 현재 문서의 {{glossary("origin", "출처")}}에서 도메인 부분을 설정하거나 가져옵니다.
domain 속성을 성공적으로 설정하면 출처의 포트를 {{jsxref("null")}}로 설정합니다.
const domainString = document.domain document.domain = domainString
현재 문서 출처의 도메인 부분.
SecurityErrordomain을 변경하려 시도한 경우.
nullhttp://developer.mozilla.org/en-US/docs/Web 주소에서, 다음 코드는 currentDomain 변수에 "developer.mozilla.org" 문자열을 할당합니다.
const currentDomain = document.domain;
어느 문서, 예컨대 www.example.xxx/good.html 등이 www.example.com의 도메인을 가지고 있을 때, 다음 예제는 창을 닫으려 시도합니다.
const badDomain = "www.example.xxx";
if (document.domain == badDomain) {
// 예시에 불과 (window.close()는 아무것도 하지 않을 수도 있음)
window.close();
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG','origin.html#relaxing-the-same-origin-restriction','Document.domain')}} | {{Spec2('HTML WHATWG')}} |