HTML DOM Anchor protocol Property



The HTML DOM Anchor protocol property is used to set or return the protocol of a link in the href attribute.

Following is the syntax to set the protocol property −

anchorObj.protocol = protocol_url

Above, protocol_url is the protocol of the URL. The values can be http, https, ftp, etc.

Following is the syntax to return the protocol property −

anchorObj.protocol

Let us now see an example to implement the DOM Anchor protocol property −

Example

 Live Demo

<!DOCTYPE html> <html> <body> <h1>Demo Heading</h1> <p>Link = <a id="mylink" hreflang="en" href="https −//abc.com −6064/abc.html/#new">Services</a></p> <h2 id="myid"></h2> <button onclick="display1()">Display pathname</button> <button onclick="display2()">Display hreflang</button> <button onclick="display3()">Display port</button> <button onclick="display4()">Display protocol</button> <script> function display1() { var a = document.getElementById("mylink").pathname; document.getElementById("myid").innerHTML = a; } function display2() { var a = document.getElementById("mylink").hreflang; document.getElementById("myid").innerHTML = a; } function display3() { var a = document.getElementById("mylink").port; document.getElementById("myid").innerHTML = a; } function display4() { var a = document.getElementById("mylink").protocol; document.getElementById("myid").innerHTML = a; } </script> </body> </html>

Output

Click on the “Display Protocol” button −


Updated on: 2019-07-30T22:30:26+05:30

151 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements