Created
August 4, 2014 19:53
-
-
Save adamculpepper/de1414dfc4fa5ce925ef to your computer and use it in GitHub Desktop.
URL Variables
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
// 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