Javascript Reference - HTML DOM Area port Property








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

Browser Support

port Yes Yes Yes Yes Yes

Syntax

Return the port property:

var v = areaObject.port 

Set the port property:

areaObject.port = port;

Property Values

Value Description
port Set the port number for URL




Return Value

A String representing the port number of the URL.

Example

The following code shows how to get the port number of the URL for a specific area in an image-map:


<!DOCTYPE html>
<html>
<body>
<!-- ww w  . ja  v  a  2  s .co  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").port;
    document.getElementById("demo").innerHTML = "Port: " + x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the port number of the URL for a specific area in an image-map.


<!DOCTYPE html>
<html>
<body>
<!--  w w  w. j a v  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" target="_blank" shape="circle" 
      coords="124,58,8" alt="myImage" href="http://www.example.com:80/test.htm">
</map>
<p id="demo"></p>

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

<script>
function myFunction() {
    document.getElementById("myArea").port = "1234";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows: