Open In App

HTML DOM Anchor protocol Property

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:  



anchorObject.protocol
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.  




<!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: 

Example 2: This example sets the Anchor protocol Property. 




<!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:  

Supported Browsers:


Article Tags :