Web API URL.search Property
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 > |
chevron_right
filter_none
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 > |
chevron_right
filter_none
Output:
Supported Browsers:
- Safari
- Opera
- Chrome
- Edge
- Firefox