Open In App

HTML DOM Anchor protocol Property

Improve
Improve
Like Article
Like
Save
Share
Report

The Anchor protocol Property in HTML DOM is used to set or return the value of the protocol part of the href attribute value. The protocol is used to specify how data are transmitted between two computers. 

Syntax:  

  • It returns the Anchor protocol property. 
anchorObject.protocol
  • It is used to set the Anchor protocol property. 
anchorObject.protocol = protocol

Property Values: It contains single value protocol which specify how data are transmitted between two computers. For ex: file, ftp, http, https, mailto etc.

Return Value: It returns a string value which represents the protocol part of the URL and also included the colon sign(:).

Example 1: This example returns the Anchor protocol Property.  

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Anchor protocol Property
    </title>
</head>
 
<body style="text-align: center;">
    <h1>GeeksforGeeks</h1>
 
    <h2>DOM Anchor protocol Property</h2>
 
    <p>Welcome to
        <a href="https://www.geeksforgeeks.org/"
            id="GFG">
            GeeksforGeeks
        </a>
    </p>
 
    <button onclick="myGeeks()">
        Submit
    </button>
 
    <p id="sudo"></p>
 
    <!-- Script to return Anchor protocol Property -->
    <script>
        function myGeeks() {
            let x = document.getElementById("GFG").protocol;
            document.getElementById("sudo").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output: 

anchor-protocol

Example 2: This example sets the Anchor protocol Property. 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Anchor protocol Property
    </title>
</head>
 
<body style="text-align: center;">
    <h1>GeeksforGeeks</h1>
 
    <h2>DOM Anchor protocol Property</h2>
 
    <p>Welcome to
        <a href="https://www.geeksforgeeks.org/"
            id="GFG">
            GeeksforGeeks
        </a>
    </p>
 
    <button onclick="myGeeks()">
        Submit
    </button>
 
    <p id="sudo"></p>
 
    <!-- Script to set Anchor protocol Property -->
    <script>
        function myGeeks() {
            let x = document.getElementById("GFG")
                .protocol = "http";
 
            document.getElementById("sudo").innerHTML =
            "The Protocol Attribute Value Change to " + x;
        }
    </script>
</body>
 
</html>


Output:  

anchor-protocol-2

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Last Updated : 02 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads