Last active
March 26, 2019 05:19
-
-
Save kylefdoherty/271de3fd05ed1ccff6fc30a7f581dcd3 to your computer and use it in GitHub Desktop.
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
/* | |
* 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