Get current page host name in JavaScript

Description

The following code shows how to get current page host name.

Example


<!--from   ww w  . j  av  a 2 s  .  com-->
<!DOCTYPE HTML>
<html>
<body>
<script>
document.writeln("hostname: " + document.location.hostname);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get current page host name in JavaScript