You are here: Reference > JavaScript > client-side > HTML DOM > properties > domain (document)

domain property (document)

Browser support:
Sets or returns the hostname of the server that served the current document.
Because of security restrictions, the contents of a document can be accessed from another document only if the two documents are located in the same domain. To ensure that security cannot be compromised, the domain property can only be set to the current or a higher-level domain. For example, the is a subdomain of the domain, therefore the domain property can be changed from to


You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that specifies or retrieves the domain.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the domain property:
    <script type="text/javascript">
        function Init () {
            var info = document.getElementById ("info");
            info.innerHTML = "The host of the current document:<br />" + document.domain;
<body onload="Init ();">
    <div id="info" style="background-color:#e0b0b0;"></div>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content