Last active
December 19, 2015 15:39
-
-
Save fuzzyfox/5977598 to your computer and use it in GitHub Desktop.
JavaScript: getQueryVariable
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
var getQueryVariable = function(variable, queryString){ | |
queryString = queryString || window.location.search; | |
var query = queryString.substr(1), | |
vars = query.split('&'), | |
pairs; | |
for(var i = 0, j = vars.length; i < j; i++){ | |
pairs = vars[i].split('='); | |
if(decodeURIComponent(pairs[0]) == variable){ | |
return decodeURIComponent(pairs[1]); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment