Created
July 30, 2019 19:11
-
-
Save sudikrt/e9ae9f597d1d9a5874de11abef1c1dce 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
/*Source : | |
https://gomakethings.com/getting-all-query-string-values-from-a-url-with-vanilla-js/ | |
*/ | |
/* @param {String} url The URL | |
* @return {Object} The URL parameters | |
*/ | |
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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment