Created
November 14, 2014 21:30
-
-
Save stuntbox/d492e358f751598ca32b to your computer and use it in GitHub Desktop.
Query String Catcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*- 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