What is Protocol?
A network protocol defines rules and conventions for communication between network devices. By adopting these rules, two devices can communicate with each other and can interchange the information.
Syntax:
location.protocol
Properties:
- ftp: The File Transfer Protocol (FTP) is a standard network protocol used for the transfer of computer files between a client and server on a computer network.
- http: The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed system.
- https: The Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP) for secure communication and widely used in Internet.
- file: It is used for file or in local server system.
- mailto: It is used in mail system.
Return Value: The protocol property returns the protocol of the current URL, including the colon (:).
Below example illustrates the location.protocol property in JavaScript:
Example:
<!DOCTYPE html> <html> <head> <title>Location protocol property</title> <style> #Gfg { position: center; width: 220px; height: 50px; color: green; } </style> <script> // Function that tells the Protocol // of current url. function Protocol() { var gfg = location.protocol; alert("protocol is: " + gfg); } </script> </head> <body> <div id = "Gfg"> <h1>GeeksforGeeks</h1> </div> <p>Click to know the protocol of current URL.</p> <button onclick = "Protocol()">Protocol</button> </body> </html> |
Output:

Recommended Posts:
- Javascript | MouseEvent which Property
- JavaScript | Cursor property
- JavaScript | Math.LN2 property
- JavaScript | Math.PI Property
- JavaScript | MouseEvent Button Property
- JavaScript | typedArray.byteOffset property
- JavaScript | MouseEvent shiftKey Property
- JavaScript | Math.LOG10E property
- Javascript | MouseEvent altKey Property
- JavaScript | Date.prototype property
- JavaScript | Math.SQRT2 property
- JavaScript arrayBuffer.slice() property
- JavaScript | Math.LOG2E property
- JavaScript | Math.SQRT1_2 property
- JavaScript | arrayBuffer.byteLength property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



