Horje
Web API URL.protocol Property

The Web API URL.protocol property is used to get USVString containing the protocol scheme of the URL. 

Syntax:

var str = URL.protocol

Return Value: This property returns a USVString containing the protocol scheme of the URL.

Example 1:

HTML

<!DOCTYPE html>
<html>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <button onclick="get()">
        Click on Me!
    </button>
  
    <script type="text/javascript">
        function get() {
            var url = new URL(
  
            console.log(
                "protocol of current URL is :",
                url.protocol);
        }
    </script>
</body>
  
</html>

Output:

Example 2:

HTML

<!DOCTYPE html>
<html>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <div id="abc"></div>
  
    <br><br>
    <button onclick="get()">
        Click on Me!
    </button>
  
    <script type="text/javascript">
        function get() {
            var url = new URL(
  
            a = document.getElementById("abc");
  
            a.innerHTML = 
                "protocol of current URL is : " 
                + url.protocol;
        }
    </script>
</body>
  
</html>

Output:

Supported Browsers:

  • Safari
  • Opera
  • Chrome
  • Edge
  • Firefox



Reffered: https://www.geeksforgeeks.org


HTML

Related
SVG operator Attribute SVG operator Attribute
SVG numOctaves Attribute SVG numOctaves Attribute
SVG restart Attribute SVG restart Attribute
SVG &lt;mask&gt; Element SVG &lt;mask&gt; Element
HTML5 MathML displaystyle Attribute HTML5 MathML displaystyle Attribute

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9