Skip to content

Instantly share code, notes, and snippets.

@adamculpepper
Created August 4, 2014 19:53
Show Gist options
  • Save adamculpepper/de1414dfc4fa5ce925ef to your computer and use it in GitHub Desktop.
Save adamculpepper/de1414dfc4fa5ce925ef to your computer and use it in GitHub Desktop.
URL Variables
// usage
// url: http://jsfiddle.net/?test=pirates%20&%20ninjas
// url: http://jsfiddle.net/?test=pirates & ninjas
var vars = [], hash;
var q = document.referrer.split('?')[1];
if(q != undefined){
q = q.replace("%20&%20", "%20%26%20") //Fix for passing ampersands through the URL
q = q.split('&');
for(var i = 0; i < q.length; i++){
hash = q[i].replace("%20%26%20", " & "); //Fix for passing ampersands through the URL
hash = hash.split('=');
vars.push(hash[1]);
vars[hash[0]] = hash[1];
}
}
alert(vars['test']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment