The domain
property returns the domain name
for the current document.
domain |
Yes | Yes | Yes | Yes | Yes |
document.domain
A String type value that represents the domain name for the current document, or null if the domain of the document cannot be identified.
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: