HTML | DOM Location Search Property

The Location Search property in HTML DOM is used to set or return the query part of URL including question mark. The query part is the part of URL after the question mark.

Syntax:

  • It returns the location search property.
    location.search
  • It is used to set the location search property.
    location.search = searchString

Property Value: searchString which is used to specify the search part of URL.



Return Value: It returns a string which represents the search value.

Example: This example display the search part of URL.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM Location search Property
    </title>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
      
    <h2>
        HTML DOM Location search Property
    </h2>
      
    <button onclick="myGeeks()">Click Here!</button>
      
    <!-- script to return location search property -->
    <script>
        function myGeeks() {
            const url = document.createElement('a');
              
            url.setAttribute('href', 
      
            window.alert("URL search value of current page: "
                    + url.search);
        }
    </script>
</body>
  
</html>                                

chevron_right


Output:

Supported Browsers: The browser supported by DOM Location search Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.