Javascript Reference - Location search Property








The querystring part is the part of the URL after the question mark (?).

The search property sets or gets the querystring part of a URL, including the question mark (?).

Browser Support

search Yes Yes Yes Yes Yes

Syntax

Return the search property.

var v = location.search

Set the search property.

location.search=querystring




Parameter Values

Value Type Description
querystring String Set the search part of the URL

Return Value

A String type value representing the querystring part of a URL, including the question mark (?).

Example


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--  w w w. j a v  a  2 s. c  o  m-->
    var x = location.search;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: