Blog Detail

Query String using JQuery

28 Jan 11
admin
No Comments
Hai,

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

$.extend({
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.push(hash[0]);
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