Javascript Reference - HTML DOM domain Property








The domain property returns the domain name for the current document.

Browser Support

domain Yes Yes Yes Yes Yes

Syntax

document.domain

Return Value

A String type value that represents the domain name for the current document, or null if the domain of the document cannot be identified.





Example

The following code shows how to get the domain name for the loaded document.


<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--from w  ww .  jav a  2s .  c  o  m-->
{
    var x = document.getElementById("demo");
    x.innerHTML=document.domain;
}
</script>

</body>
</html>

The code above is rendered as follows: