Visit Mozilla.org

DOM:document.domain

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Gets/sets the domain of the current document.

[edit] Syntax

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

[edit] Example

// for document www.love.com/good.html,
// this script closes the window
var badDomain = "www.love.com";
if (document.domain == badDomain)
   window.close();
// For the URI http://developer.mozilla.org/en/docs/DOM the
// following sets domain to the string "developer.mozilla.org"
var domain = document.domain;

[edit] 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, all common browsers including Mozilla will let you set it to a superdomain of the current value. For example, on developer.mozilla.org it is possible to set it to "mozilla.org" but not "mozilla.com".

It is not universally possible in all browsers to set document.domain to a top-level domain (such as "com" or "org") or to a subdomain of a domain on which registrations are restricted (e.g. "co.uk", as registrations on the "uk" domain are restricted).

[edit] References

Scripts and the Same Origin Policy

[edit] Specification

DOM Level 2 HTML: document.domain