I wrote a function in this answer to a similar question that should help you. I voted to close this as a duplicate of that question, but now I see that there are extra requirements in this one. When I wrote that answer, I made a version that will handle array-style URL parameters too:
(function () {
var e,
d = function (s) { return decodeURIComponent(s).replace(/\+/g, " "); },
q = window.location.search.substring(1),
r = /([^&=]+)=?([^&]*)/g;
while (e = r.exec(q)) {
if (e[1].indexOf("[") == "-1")
urlParams[d(e[1])] = d(e[2]);
else {
var b1 = e[1].indexOf("["),
aN = e[1].slice(b1+1, e[1].indexOf("]", b1)),
pN = d(e[1].slice(0, b1));
if (typeof urlParams[pN] != "object")
urlParams[d(pN)] = {},
urlParams[d(pN)].length = 0;
if (aN)
urlParams[d(pN)][d(aN)] = d(e[2]);
else
Array.prototype.push.call(urlParams[d(pN)], d(e[2]));
}
}
})();
You can see a working demo here: http://jsbin.com/adali3/2
Sample query string:
test=Hello&person[]=jeff&person[]=jim&person[extra]=john&nocache=1290122355841
Result:
{
"test": "Hello",
"person": {
"0": "jeff",
"1": "jim",
"length": 2,
"extra": "john"
},
"nocache": "1290100673882"
}