Skip to content

Instantly share code, notes, and snippets.

@fuzzyfox
Last active December 19, 2015 15:39
Show Gist options
  • Save fuzzyfox/5977598 to your computer and use it in GitHub Desktop.
Save fuzzyfox/5977598 to your computer and use it in GitHub Desktop.
JavaScript: getQueryVariable
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