Blog Detail

Query String using JQuery

28 Jan 11
No Comments

We can write an extension for Jquery to get querystring(parameter) values of a url.
Extension of JQuery as follows.

getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf(‘?’) + 1).split(‘&’);
for(var i = 0; i < hashes.length; i++)
hash = hashes[i].split(‘=’);
vars[hash[0]] = hash[1];
return vars;
getUrlVar: function(name){
return $.getUrlVars()[name];

You need to inclue above code in your JQuery file.You will get querystring(parameter) values of the url using follwing code in your js file.

// Getting URL var by its name
var byName = $.getUrlVar(‘name’);

Happy Programing…

Leave A Comment