Javascript 提供了文档对象来获取有关文档的任何详细信息。它提供了document.domain来获取在其中加载文档的服务器的域。
在以下示例中,文档被加载到“ tutorialspoint ”服务器中。因此,我们将获得的域名是“ www.tutorialspoint.com ”。Document.domain是一个内置函数,用于获取在其中加载文档的服务器的域。在“ tutorialspoint” 服务器中使用此方法时,将加载有关“ tutorialspoint” 的域,如输出所示。
<html>
<body>
<p id="domain"></p>
<script>
document.getElementById("domain").innerHTML =
'The domain name is :'+" "+document.domain;
</script>
</body>
</html>输出结果
The domain name is www.tutorialspoint.com