Last active
December 12, 2015 10:39
-
-
Save craiga/4760400 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Parse query string into an object. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/4760400 | |
*/ | |
function parseQueryString(unparsed) { | |
if(typeof unparsed == "undefined") { | |
unparsed = window.location.search; | |
} | |
unparsed = unparsed.replace(/^\?/, ""); | |
var parsed = {}; | |
var keyValuePairs = unparsed.split(/&/m); | |
var numKeyValuePairs = keyValuePairs.length; | |
for(var keyValuePairIndex = 0; keyValuePairIndex < numKeyValuePairs; keyValuePairIndex++) { | |
var keyValuePair = keyValuePairs[keyValuePairIndex].split(/=/); | |
if(keyValuePair.length == 2) { | |
var key = keyValuePair[0]; | |
var value = keyValuePair[1]; | |
parsed[key] = value; | |
} | |
} | |
return parsed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment