Location host Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location

Description

The host property sets or gets the hostname and port of a URL.

Set the host property with the following Values

Value Type Description
hostname:port String Sets the hostname and port number of the URL

Return Value

A String, representing the domain name and port number, or the IP address of a URL

The following code shows how to return the hostname and port of the current URL:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//from  ww w.  ja  va 2s .  c o m
    var x = location.hostname;
    document.getElementById("demo").innerHTML= x;
}
</script>

</body>
</html>

Related Tutorials