Doesn't handle multiple values (e.g. form?foo=yes&foo=no)
I'm pissed that "hello".replace("l", "w") == "hewlo"
Also pissed that decode("hello+world") != "hello world"
function getrequestargs(url) {
var args = new Object();
url = String(url);
var idx = url.indexOf("?");
if (idx >= 0) {
var s = url.substring(idx + 1);
var pairs = s.split("&");
for (var i = 0; i < pairs.length; i++) {
var idx = pairs[i].indexOf("=");
if (idx > 0) {
pairs[i] = pairs[i].replace(/\+/g, " ");
var key = decodeURI(pairs[i].substring(0, idx));
var value = decodeURI(pairs[i].substring(idx + 1));
args[key] = value;
}
}
}
return args;
}
var args = getrequestargs(location);
0 comments:
Post a Comment