Skip to content
Related Articles

Related Articles

Web API URL.search Property
  • Last Updated : 27 Nov, 2020

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:



Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Supported Browsers:

  • Safari
  • Opera
  • Chrome
  • Edge
  • Firefox

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :