Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Query String Catcher
/*- Query String Values ------------------------------------------------------*/
//
// Retrieves, parses URL query string values into an object using JS.
// See "JavaScript: The Definitive Guide", 5th ed, p.272, example 14-1.
var queryStringValues = getQueryStringValues();
function getQueryStringValues() {
// var args = new Object();
var args = {};
var query = location.search.substring(1);
var pairs = query.split("&");
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf("=");
if (pos == -1) continue;
var argName = pairs[i].substring(0, pos);
var value = pairs[i].substring(pos + 1);
value = decodeURIComponent(value);
args[argName] = value;
}
return args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment