Open In App

Web API URL.search Property

Last Updated : 27 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The Web API URL.search property is used to get USVString which is a search string or a query string. This string contains a “?” followed by the parameters of the URL.

Syntax:

var str = URL.search

Return Value: This property returns a USVString search string.

Example 1:

HTML




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


Output:

Example 2:

HTML




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


Output:

Supported Browsers:

  • Safari
  • Opera
  • Chrome
  • Edge
  • Firefox


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads