Friday, March 21, 2014

How to get querystring value using jQuery

In this post, I will show you how to get the QueryString variable value using jQuery. I have created a function which returns value of any querystring variable.

Earlier I had posted about Get Page Title and URL using jQuery, Get previous page URL using jQuery, Check for '#' hash in URL using jQuery, Style Hyperlinks based on URL extension and Use protocol less URL for referencing jQuery.

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}​

No comments:

Post a Comment