Created
July 21, 2010 04:30
-
-
Save choonkeat/484068 to your computer and use it in GitHub Desktop.
get_params.js
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
| (function(url_parts, params) { | |
| var query_string = (url_parts && url_parts[1]); | |
| if (! query_string) return; | |
| var pairs = query_string.split('&'); | |
| for (var x = 0; x < pairs.length; x++) { | |
| var kv = pairs[x].split('='); | |
| params[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]); | |
| } | |
| // do useful with params | |
| })(window.location.href.split('?'), {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't handle when a query string doesn't have a value, it should then return
null.See: https://github.com/sindresorhus/query-string