Created
December 2, 2016 13:22
-
-
Save SvSven/dea957e2c64f517d065d06f2027bcdbd to your computer and use it in GitHub Desktop.
JS function to get and parse URL parameters
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
// Returns an object with all URL parameters, or error message if none are found | |
function getURLParams() { | |
if(!window.location.search) { return "No URL parameters found."; } | |
var paramsArr = window.location.search.substr(1).split("&"), | |
params = {}; | |
paramsArr.forEach(function(e) { | |
var a = e.split("="); | |
params[a[0]] = a[1]; | |
}); | |
return params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment