Anchor protocol Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


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

Property Values

protocol Sets the protocol of a URL: file: ftp: http: https: mailto: etc..

Return Value

A String, representing the protocol part of the URL

The following code shows how to Return the protocol of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<p><a id="myAnchor" href="">Example link</a></p>

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

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

function myFunction() {/*from  ww  w  .  j ava 2s . co m*/
    var v = document.getElementById("myAnchor").protocol;
    document.getElementById("demo").innerHTML = v;


Related Tutorials