Last active
December 13, 2016 20:39
-
-
Save triple-j/eb238061d5be139fb55bea4b551dcd1a to your computer and use it in GitHub Desktop.
Retrieve URL Parameters <http://stackoverflow.com/a/1099670>
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
/** | |
* Retrieve URL Parameters <http://stackoverflow.com/a/1099670> | |
* @param {string} [qs=window.location.search] - Query string | |
* @returns {object} | |
* | |
* @example | |
* var query = getQueryParams(document.location.search); | |
* alert(query.foo); | |
*/ | |
function getQueryParams(qs) { | |
qs = qs || window.location.search; | |
qs = qs.split('+').join(' '); | |
var params = {}, | |
tokens, | |
re = /[?&]?([^=]+)=([^&]*)/g; | |
while (tokens = re.exec(qs)) { | |
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); | |
} | |
return params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment