Created
October 30, 2014 17:11
-
-
Save waaronking/7531b83ad8000edf0f4d to your computer and use it in GitHub Desktop.
getURLParameters
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
//Works fairly well | |
/* Get URL parameters */ | |
function getUrlParam(key) { | |
var params = [], pair; | |
var pairs = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | |
if (key) { | |
return decodeURIComponent((new RegExp('[?|&]' + key + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; | |
} else { | |
//split the key/value pairs | |
for(var i=0; i<pairs.length; i++){ | |
pair = pairs[i].split('='); | |
params.push(pair[0]); | |
params[pair[0]] = pair[1]; | |
} | |
return params; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment