Last active
December 23, 2015 08:39
-
-
Save fabriceleal/6609675 to your computer and use it in GitHub Desktop.
Get query parameters
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
function getParams() { | |
var parameters = location.search.substring(1).split('&'); // drop initial '?' and get array of 'key=value' | |
var obj = {}; | |
for(var i=0; i < parameters.length; ++i){ | |
// 0 with the key, 1 with the value | |
var keyvalue = parameters[i].split('='); | |
// this won't work well when we try to pass jsons as parameters. | |
obj[ decodeURIComponent(keyvalue[0]) ] = decodeURIComponent(keyvalue[1]); | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this instead: https://github.com/chrissrogers/jquery-deparam/blob/master/jquery-deparam.js