Javascript Browser Location search Property

Introduction

Return the query string part of a URL.

var x = location.search;

View in separate window

<!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 search property sets or gets the query string part of a URL, including the question mark (?).

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

Property Values

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



PreviousNext

Related