JavaScript Get Query String
var QueryString =(function(w){
return {
GetVariable: function (variable) {
var query = '',
vars = [],
i = 0,
pair = '';
if (!window.location || !window.location.search) {
//No query string to search.
return "";
}
variable = variable.toLowerCase();
query = w.location.search.substring(1);
vars = query.split("&");
i = vars.length - 1;
//Reverse loops execute faster & we do not care about order
for (; i >= 0; i -= 1) {
pair = vars[i].split("=");
if (pair[0].toLowerCase() === variable) {
return pair[1];
}
}
}
};
})(window);
/*
Usage
Url - http://localhost/index.html?pageNum=100
var x = QueryString.GetVariable("pageNum");
x will equal 100
*/