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:Â Â
- 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
id = "GFG" >
GeeksforGeeks
</ a >
</ p >
< button onclick = "myGeeks()" >
Submit
</ button >
< p id = "sudo" ></ p >
< 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.Â
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
id = "GFG" >
GeeksforGeeks
</ a >
</ p >
< button onclick = "myGeeks()" >
Submit
</ button >
< p id = "sudo" ></ p >
< 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:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Last Updated :
02 Jan, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...