상세 컨텐츠

본문 제목

document.domain 속성

프로그래밍/스크립트

by 라제폰 2009. 2. 6. 16:55

본문

인수
sVal : (속성 문자열)
domain 속성값은 현재 문서가 있는 서버의 도메인 이름을 나타내는 문자열이다.

이 속성은 읽기/쓰기이며 디폴트값은 없다.

설명

도메인 이름는 디폴트로 서버 정보에서 얻어지나 그 이름의 suffix 만은 수정 설정될 수 있다.
이는 같은 도메인 이름 속에서 suffix 만 다른 서버들간에 script 속성들의 공유와 보안관리를 하는데 사용될 수 있다.

구문
document.write(location.domain)
document.links[0].domain='domainString'
특기

도메인 이름의 변경은 아주 제한적이다.
URL 주소 'search.koxo.com'로 부터 문서를 읽었다면, domain 속성으로 'koxo.com'으로는 변경시킬 수는 있으나, 'search.koxo'으로는 변경시킬 수 없다.

'search.koxo.com'에서 문서를 읽었을때
document.domain='koxo.com' 가능
document.domain='search.koxo' 불가
document.domain='koxo.net' 불가

특기

이 속성은 초기에 문서가 있는 서버의 호스트 이름을 반환하였다. 프레임들간에 페이지들을 공유하기위해 도메인 서픽스(suffix)와 연관된 할당을 할 수 있다. 예를 들면, subname.domain.com에 있는 프레임의 페이지와 새로운 www.domain.com의 페이지가 당초에는 서로 교류할 수 없었다. 그러나 domain 속성을 양쪽 페이지에 서픽스 domain.com으로 하면 두 페이지가 모두 안전한 것으로 고려할수 있어 상호 접속할 수 있게 된다.

domain 속성을 설정할 때는 사용자 브라우저에서 판정된 것이 아니고 서버의 것을 사용하여야 한다.

다른 호스트에 있는 모든 페이지들은 명시적으로 같은 domain 속성을 지정하여야 상호 교류할 수 있다. 예를 들어 microsoft.com 호스트상의 페이지에는 domain 속성값 디폴트가 "microsoft.com"이된다. 다른 호스트인 msdn.microsoft.com 이름의 호스트에 있는 페이지에 domain 속성값을 "microsoft.com"로 설정하면 두 페이지는 상호 교류할 수 있다. 그러나 microsoft.com에 있는 페이지에 "microsoft.com"으로 반드시 domain 속성값을 명시적으로 을 지정하여야 한다.

더욱 이 속성은 다른 도메인 서픽스들을 프레임간 교류하여 사용될 수 없다. 예를들면 www.microsoft.com에 있는 한 프레임의 페이지와 www.msn.com에 있는 다른 페이지의 프레임사이에서 양쪽에 모두 domain 속성값을 "microsoft.com"으로 설정하더라도 상호 교류될 수 없다.

안전 경고 : 이 속성을 잘못사용하면 보안문제가 일어날 수 있다. domain 속성값은 반드시 상호 교류가 허용되어야 할 경우에만 서버에서 판정한 값을 사용하라. 이 속성을 사용자 컴퓨터에서 location 개체를 사용하여 얻어 설정하는 경우 사이트가 Domain Name System (DNS)를 통하여 공격을 받을 수 있다.
적용
개체 script HTML 규격 IE
document document.domain[=sVal] 없슴 없슴 IE4.0(win16,win32,ce,unix,mac)

참고

(영문) W3C DOM Level 1(Document Object Model).


property
domain 속성
domain</b> 속성 이전페이지로페이지 맨위로페이지 맨아래로

간단한 domain 속성 예제

http://tong.nate.com/boxitem/post.do?action=list&_boxID=83928&_tongID=43496 nate.com
http://tong.nate.com/boxitem/post.do?action=clist&_boxID=83928&_tongID=43496 nate.com
http://tong.nate.com/boxitem/post.do?action=plist&_boxID=83928&_tongID=43496 nate.com
javascript:PopupPrintView(43496,83928,8275494) nate.com
http://tong.nate.com/rahxephon/8275494 nate.com
javascript:CopyDetailUrl('http://tong.nate.com/rahxephon/8275494') nate.com
javascript:ViewPoliceLayer(); nate.com
http://koxo.com/lang/js/object/location.html nate.com
http://koxo.com/lang/js/object/document.html nate.com
http://koxo.com/lang/js/property/protocol.html nate.com
http://koxo.com/lang/js/property/host.html nate.com
http://koxo.com/lang/js/property/hostname.html nate.com
http://koxo.com/lang/js/property/port.html nate.com
http://koxo.com/lang/js/property/pathname.html nate.com
http://koxo.com/lang/js/property/hash.html nate.com
http://koxo.com/lang/js/property/search.html nate.com
http://koxo.com/lang/js/property/href.html nate.com
http://koxo.com/lang/js/property/URL.html nate.com
http://koxo.com/lang/js/property/domain.html nate.com
http://koxo.com/lang/js/property/target.html nate.com
http://www.w3.org/tr/2000/wd-dom-level-1-20000929/ nate.com
http://koxo.com/lang/js/property/jsList.html nate.com
javascript:history.back() nate.com
http://koxo.com/lang/js/property/domain.html#topJump nate.com
http://koxo.com/lang/js/property/domain.html#bottomJump nate.com

document.domain=nate.com
http://koxo.com/lang/js/property/jsList.html koxo.com
http://koxo.com/lang/js/property/domain.html#sampleJump koxo.com
javascript:history.back() koxo.com
http://koxo.com/lang/js/property/domain.html#bottomJump koxo.com
http://koxo.com/lang/js/object/document.html koxo.com
http://koxo.com/lang/js/object/location.html koxo.com
http://koxo.com/lang/js/object/document.html koxo.com
http://koxo.com/lang/js/property/protocol.html koxo.com
http://koxo.com/lang/js/property/host.html koxo.com
http://koxo.com/lang/js/property/hostname.html koxo.com
http://koxo.com/lang/js/property/port.html koxo.com
http://koxo.com/lang/js/property/pathname.html koxo.com
http://koxo.com/lang/js/property/hash.html koxo.com
http://koxo.com/lang/js/property/search.html koxo.com
http://koxo.com/lang/js/property/href.html koxo.com
http://koxo.com/lang/js/property/URL.html koxo.com
http://koxo.com/lang/js/property/domain.html koxo.com
http://koxo.com/lang/js/property/target.html koxo.com
http://www.w3.org/tr/2000/wd-dom-level-1-20000929/ koxo.com
http://koxo.com/lang/js/property/jsList.html koxo.com
javascript:history.back() koxo.com
http://koxo.com/lang/js/property/domain.html#topJump koxo.com
http://koxo.com/lang/js/property/domain.html#bottomJump koxo.com

document.domain=koxo.com
<A href="http://trio.co.kr/cgi/bbs/triobbs.cgi?db=triobbs">trio 게시판</A><BR>
<SCRIPT>
for (i=0;i<document.links.length;i++){
  document.write(document.links[i].href+' <FONT color=blue>'+
    document.links[i].document.domain+'</FONT><BR>');
}
document.write('<BR>document.domain=<FONT color=red>'+document.domain+'</FONT><BR>');
</SCRIPT>

관련글 더보기