일반 document.domain (from mozilla.org)

황제낙엽 2013.03.13 15:56 조회 수 : 407

sitelink1  
sitelink2  
sitelink3 http://1 
sitelink4 http://ko 
extra_vars5 https://developer.mozilla.org/ko/docs/DOM/document.domain 
extra_vars6 sitelink1 

Summary

Gets/sets the domain portion of the origin of the current document, as used by the same origin policy.

Syntax

var domainString = document.domain;
document.domain = string;

Example

1
2
3
4
5
6
// for document www.example.xxx/good.html,
// this script closes the window
var badDomain = "www.example.xxx";
if (document.domain == badDomain)
window.close(); // Just an example - window.close() sometimes has no effect.
1
2
3
// For the URI http://developer.mozilla.org/en/docs/DOM the
// following sets domain to the string "developer.mozilla.org"
var domain = document.domain;

Notes

This property returns null if the domain of the document cannot be identified.

In the DOM HTML specification, this property is listed as being read-only. However, Mozilla will let you set it to a superdomain of the current value, constrained by its base domain. For example, on developer.mozilla.org it is possible to set it to "mozilla.org" but not "mozilla.com" or "org". See the implementation (line number may rot).

Mozilla distinguishes a document.domain property that has never been set from one explicitly set to the same domain as the document's URL, even though the property returns the same value in both cases. One document is allowed to access another if they have both set document.domain to the same value, indicating their intent to cooperate, or neither has set document.domain and the domains in the URLs are the same (implementation). Were it not for this special policy, every site would be subject to XSS from its subdomains (for example, https://bugzilla.mozilla.org could be attacked by bug attachments on https://bug*.bugzilla.mozilla.org).

Specification

See also



<한글 레퍼런스>
http://pakss328.blogspot.kr/2012/03/javascript.html
http://myheartu1.blog.me/140121043378
http://blog.naver.com/dlfdlwlfyd?Redirect=Log&logNo=30111900752
http://cafe.naver.com/webprogrammer2/43
http://support.microsoft.com/kb/813819/ko (IE6에서는 document.domain 가 지원되지 않습니다)