Getting Query String Values using JavaScript or jQuery | JavaScript Tutorial | JavaScript Programmer Guide

We can easily get the query string value by accessing the window.location in JavaScript. The below code snippet provides a JavaScript function that reads the query string parameter password to the function



01function GetQueryStringParams(sParam)
02{
03    var sPageURL = window.location.search.substring(1);
04    var sURLVariables = sPageURL.split('&');
05    for (var i = 0; i < sURLVariables.length; i++)
06    {
07        var sParameterName = sURLVariables[i].split('=');
08        if (sParameterName[0] == sParam)
09        {
10            return sParameterName[1];
11        }
12    }
13}​

Considering below Url as an example,
http://www.ProgrammerGuide.Net/?technology=jquery&blog=jquerybyexample

You can simply call the JavaScript function below by passing the query string variable name:

1//
2var tech = GetQueryStringParams('technology');
3var blog = GetQueryStringParams('blog');
4//