Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Last active August 5, 2017 21:11
Show Gist options
  • Save bryceadams/98ca5e33701b4831f256 to your computer and use it in GitHub Desktop.
Save bryceadams/98ca5e33701b4831f256 to your computer and use it in GitHub Desktop.
JavaScript get URL params
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
// URL: http://mywebsite.com?troll=true&serious=yes
getUrlVars()['troll'] // true
getUrlVars()['serious'] // yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment