Skip to content

Instantly share code, notes, and snippets.

@stuntbox
Created November 14, 2014 21:30
Show Gist options
  • Save stuntbox/d492e358f751598ca32b to your computer and use it in GitHub Desktop.
Save stuntbox/d492e358f751598ca32b to your computer and use it in GitHub Desktop.
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