Home >Web Front-end >HTML Tutorial >The Chinese translation of HTML DOM Anchor protocol Property is 'HTML DOM anchor protocol property'
HTML DOM Anchor protocol attribute is used to set or return the protocol linked in the href attribute.
The following is the syntax for setting the protocol attribute -
anchorObj.protocol = protocol_url
Above, protocol_url is the protocol of the URL. Values can be http, https, ftp, etc.
The following is the syntax for returning protocol attributes-
anchorObj.protocol
Now let us look at an example of implementing the DOM Anchor protocol attribute-
Live demonstration
<!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>
Click the "Show Protocol" button -
The above is the detailed content of The Chinese translation of HTML DOM Anchor protocol Property is 'HTML DOM anchor protocol property'. For more information, please follow other related articles on the PHP Chinese website!