Get current page host in JavaScript

Description

The following code shows how to get current page host.

Example


<!--from  w w  w. jav  a  2 s  .c o m-->
<!DOCTYPE HTML>
<html>
<body>
<script>
document.writeln("host: " + document.location.host);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get current page host in JavaScript