Get current query string in the URL in JavaScript

Description

The following code shows how to get current query string in the URL.

Example


<!-- w  w  w.  j  a  v a 2  s.c o m-->
<!DOCTYPE HTML>
<html>
<body>
<script>
document.writeln("search: " + document.location.search);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get current query string in the URL in JavaScript