HTML - DOM Document domain Property



The domain property is used for getting the domain name of the server on which the document is currently being executed. We can only get the domain name of the server, setting or modifying the domain name, it is deprecated now.

Syntax

document.domain;

Return value

It returns a String value which represents the domain name of the server running the HTML document and returns null if the domain cannot be identified.

Example of HTML DOM Document 'domain' Property

The following example retuens the domain name of server running this document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM document domain Property
    </title>
</head>
<body>
    <button onclick="fun()">Click me</button>
    <p id="domain"></p>
    <script>
        function fun() {
            let x = document.domain;
            document.getElementById("domain").innerHTML =
                "Domain name of server: " +x;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
domain Yes 1 Yes 12 Yes 1 Yes 1 Yes 12.1
html_dom.htm
Advertisements