Created
June 28, 2011 10:33
-
-
Save dankempster/1050870 to your computer and use it in GitHub Desktop.
Get Query String value with jQuery
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
/** | |
* Sourced from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript#answer-3855394 | |
* @author BrunoLM <brunolm at codingwise dot com> | |
*/ | |
(function($) { | |
$.queryString = (function(a) { | |
if (a == "") return {}; | |
var b = {}; | |
for (var i = 0; i < a.length; ++i) | |
{ | |
var p=a[i].split('='); | |
if (p.length != 2) continue; | |
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); | |
} | |
return b; | |
})(window.location.search.substr(1).split('&')) | |
})(jQuery); |
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
// Usage: | |
$.queryString["param"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You shouldn't use jQuery for this.
Here's a plain JS module:
https://github.com/sindresorhus/query-string