Friday, June 12, 2026
HomeLanguagesJavascriptJavaScript Location protocol Property

JavaScript Location protocol Property

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 information. The protocol property sets or returns the protocol of the current URL, including the colon (:).

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 systems.
  • https: The Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP) for secure communication and is widely used on the Internet.
  • file: It is used for files or in the local server system.
  • mailto: It is used in the mail system.

Return Value: It returns a string(The protocol property returns the protocol of the current URL, including the colon (:)).

Example: 

HTML




<body style="align-items: center; margin-left: auto;
                       justify-content: center;">
    <div>
        <h1 id="Gfg" style="color: green;">
            neveropen
          </h1>
        <p>
            Click to know the protocol of current URL.
          </p>
        <button onclick="Protocol()">
            Protocol
          </button>
    </div>
    <script>
      function Protocol() {
          var gfg = location.protocol;
          alert("protocol is: " + gfg);
      }
    </script>
</body>


Output:

 

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS