Created
May 6, 2018 16:36
-
-
Save aindong/8d0af92d6b077f7afeaa35c38fb0ec5b to your computer and use it in GitHub Desktop.
Get the query string from url using javascript es6
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 qs = (function(a) { | |
if (a == "") return {}; | |
var b = {}; | |
for (var i = 0; i < a.length; ++i) | |
{ | |
var p=a[i].split('=', 2); | |
if (p.length == 1) | |
b[p[0]] = ""; | |
else | |
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); | |
} | |
return b; | |
})(window.location.search.substr(1).split('&')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example usage
http://yourwebsite.com/?user=199
qs['user']