Horje
Web API URL.username Property

The Web API URL.username property returns a USVString containing the username specified before the domain name of the URL

Syntax:

var str = URL.username

Return Value: This property returns a USVString containing the username specified before the domain name 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("username of current URL is :", 
                url.username);
        }
    </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 = "username of current URL is : "
                + url.username;
        }
    </script>
</body>
  
</html>

Output:

Supported Browsers:

  • Safari
  • Opera
  • Chrome
  • Edge
  • Firefox



Reffered: https://www.geeksforgeeks.org


HTML

Related
Web API URL.pathname Property Web API URL.pathname Property
SVG LinearGradientElement.y2 Property SVG LinearGradientElement.y2 Property
Web API URL.port Property Web API URL.port Property
Web API URL.protocol Property Web API URL.protocol Property
SVG operator Attribute SVG operator Attribute

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