Computer >> Computer tutorials >  >> Programming >> Javascript

How to display the domain of the server that loaded a document in JavaScript?


Javascript has provided document object to get any detail regarding a document. It has provided document.domain to get the domain of the server in which document loaded.

Example

In the following example, the document is loaded in "tutorialspoint" server. Therefore the domain which we will get is "www.tutorialspoint.com". Document.domain is an inbuilt function used to get the domain of the server in which the document is loaded. When this method is used in the "tutorialspoint" server, the domain with respect to the "tutorialspoint" is loaded as shown in the output.

<html>
<body>
<p id="domain"></p>
<script>
   document.getElementById("domain").innerHTML =
   'The domain name is :'+" "+document.domain;
</script>
</body>
</html>

Output

The domain name is www.tutorialspoint.com