This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Document.domain

Document 인터페이스의 domain 속성은 동일 출처 정책에서 사용하는 현재 문서의 출처에서 도메인 부분을 설정하거나 가져옵니다.

domain 속성을 성공적으로 설정하면 출처의 포트를 null로 설정합니다.

구문

js
const domainString = document.domain;
document.domain = domainString;

현재 문서 출처의 도메인 부분.

예외

SecurityError

다음 상황에서 domain을 변경하려 시도한 경우.* 샌드박스 설정된 <iframe> 요소에 속한 문서

예제

도메인 가져오기

http://newreal1.mobosoft.fun/ko/docs/Web 주소에서, 다음 코드는 currentDomain 변수에 "newreal1.mobosoft.fun" 문자열을 할당합니다.

js
const currentDomain = document.domain;

창 닫기

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

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

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

명세

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

브라우저 호환성

같이 보기