Created
January 26, 2019 01:52
-
-
Save davidroyer/2b16bf32bcec731d3b6e7b8097fa4703 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var getParams = function (url) { | |
var params = {}; | |
var parser = document.createElement('a'); | |
parser.href = url; | |
var query = parser.search.substring(1); | |
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; | |
}; | |
/* TO USE IT: | |
getParams(window.location.href) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment