Created
November 25, 2012 15:06
-
-
Save hsribei/4143875 to your computer and use it in GitHub Desktop.
Parse url parameters from any string given or from current URL otherwise
This file contains 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
// Adapted from http://stackoverflow.com/a/901144/105132 | |
function parseUrlParams(queryString) { | |
var params = {}, | |
match, | |
pl = /\+/g, // Regex for replacing addition symbol with a space | |
search = /([^&=]+)=?([^&]*)/g, | |
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, | |
query = queryString || window.location.search.substring(1); | |
while (match = search.exec(query)) | |
params[decode(match[1])] = decode(match[2]); | |
return params; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment