Created
May 1, 2012 18:40
-
-
Save brookemckim/2570353 to your computer and use it in GitHub Desktop.
Parse query strings in javascript.
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 queryStrings = window.location.search.substring(1).split("&") | |
var params = {}; | |
for (var i = 0; i < queryStrings.length; i++) { | |
var splitParam = queryStrings[i].split("="); | |
if (splitParam.length > 1) { | |
var key = splitParam[0]; | |
var val = splitParam[1]; | |
params[key] = val; | |
} | |
} |
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