Javascript Reference - HTML DOM Area hostname Property








The hostname property sets or gets the hostname part of the href attribute value.

Browser Support

hostname Yes Yes Yes Yes Yes

Syntax

Return the hostname property:

var v = areaObject.hostname

Set the hostname property:

areaObject.hostname = hostname

Parameter

Value Description
hostname Set the hostname of a URL




Return Value

A String representing the domain name or IP address of the URL.

Example

The following code shows how to get the hostname of the URL for a specific area in an image-map.


<!DOCTYPE html>
<html>
<body>
<!-- ww  w .  j  av  a2 s . c o m-->
<img src="http://java2s.com/style/demo/border.png" width="145" 
     height="126" usemap="#myImageMap">

<map name="myImageMap">
  <area id="myArea" shape="circle" coords="124,58,8" alt="myImage" href="http://example.com">
</map>
<p id="demo"></p>

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

<script>
function myFunction() {
    var x = document.getElementById("myArea").hostname;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the hostname of a specific area in an image-map.


<!DOCTYPE html>
<html>
<body>
<!--from   w  w w.j  a  v  a2 s.  com-->
<img src="http://java2s.com/style/demo/border.png" width="145" 
     height="126" usemap="#myImageMap">

<map name="myImageMap">
  <area id="myArea" target="_blank" shape="circle" 
     coords="124,58,8" alt="myImage" href="http://example.com#description">
</map>
<p id="demo"></p>

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

<script>
function myFunction() {
    document.getElementById("myArea").host = "www.example.com";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows: