代码示例:(标识:eg_js_location_host)
<!DOCTYPE html>
<html>
<body>

<h1>window.location 对象</h1>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 
"页面主机名是:" + window.location.hostname;
</script>

</body>
</html>
运行结果: