Skip to content

Instantly share code, notes, and snippets.

@kylefdoherty
Last active March 26, 2019 05:19
Show Gist options
  • Save kylefdoherty/271de3fd05ed1ccff6fc30a7f581dcd3 to your computer and use it in GitHub Desktop.
Save kylefdoherty/271de3fd05ed1ccff6fc30a7f581dcd3 to your computer and use it in GitHub Desktop.
/*
* Based on https://css-tricks.com/snippets/javascript/get-url-variables/
* @param {String} url The URL
* @return {Object} The URL parameters if there are any, if not return undefined
*/
var getParams = function(url) {
var params = {};
var parser = document.createElement("a");
parser.href = url;
var query = parser.search.substring(1);
if (!!query) {
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
params[pair[0]] = decodeURIComponent(pair[1]);
}
return params
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment