Skip to content
Related Articles

Related Articles

JavaScript | Location protocol Property

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 14 Feb, 2019

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.




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

<!DOCTYPE html>
        <title>Location protocol property</title>
            #Gfg {
                position: center;
                width: 220px;
                height: 50px;
                color: green;
            // Function that tells the Protocol
            // of current url.
            function Protocol() {
                var gfg = location.protocol;
                alert("protocol is: " + gfg);
        <div id = "Gfg">
        <p>Click to know the protocol of current URL.</p>
        <button onclick = "Protocol()">Protocol</button>


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!