Javascript DOM HTML Anchor protocol Property get

Introduction

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

Possible Values:

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

Return the protocol of a link:

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

Click the button to return the protocol of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.java2s.com">Example link</a></p>

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

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

<script>
function myFunction() {/*w  ww  .  ja  v a 2 s  .c  om*/
  var x = document.getElementById("myAnchor").protocol;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related