Javascript DOM HTML Area protocol Property get

Introduction

The protocol property sets or gets the protocol of the href attribute value.

Property Values of protocol:

  • file:
  • ftp:
  • http:
  • https:
  • mailto:
  • etc..

Return the protocol of the URL for a specific area in an image-map:

var x = document.getElementById("myArea").protocol;

Click the button to display the protocol of the href attribute for the myArea area in the image-map.

View in separate window

<!DOCTYPE html>
<html>
<body>

<img src="image1.png" width="100" height="100" usemap="#myFlagMap">

<map name="myFlagMap">
  <area id="myArea" 
        shape="circle" 
        coords="50,50,40" 
        alt="Target" 
        href="https://www.java2s.com">
</map>/*w w  w.j a  va2 s.  c  om*/

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

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

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

</body>
</html>



PreviousNext

Related