Anchor protocol Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

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

Property Values

ValueDescription
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>
<html>
<body>

<p><a id="myAnchor" href="http://www.example.com/test.htm#part2">Example link</a></p>

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

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

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

</body>
</html>

Related Tutorials