HTML DOM domain Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM domain property is used for getting the domain name of the server on which the document is being currently executing. It returns domain name in the form of string and the value can be null if the domain is not identified.


Following is the syntax for domain property −



Let us look at an example for the HTML DOM domain property −

<!DOCTYPE html>
<h1>domain property example</h1>
<p>Get the domain name property value by clicking the below button </p>
<button onclick="getDomain()">Get domain</button>
<p id="Sample"></p>
   function getDomain() {
      var doc = document.domain;
      document.getElementById("Sample").innerHTML ="The domain name of the server running
      this document is "+doc;


This will produce the following output −

On clicking the “Get domain” button −

We have first created a “Get domain” button that will execute the getDomain() method when clicked by the user −

<button onclick="getDomain()">Get domain</button>

The getDomain() function gets the document’s domain property and assigns its value to variable doc. This variable doc is then displayed in the paragraph that has id “Sample” associated with it and used the innerHTML property to display the intended text −

function getDomain() {
   var doc = document.domain;
   document.getElementById("Sample").innerHTML ="The domain name of the server running this document is "+doc;
Published on 08-Aug-2019 17:44:02