URLを解析するためのジェネリック関数は次のとおりです。
function parseQueryString(url) {
var e,
d = function (s) {
return decodeURIComponent(s.replace(/\+/g, " "));
},
r = /([^&=]+)=?([^&]*)/g,
queryObject = {};
while (e = r.exec("url=" + url))
queryObject[d(e[1])] = d(e[2]);
console.dir(queryObject);
return queryObject;
}
URLを呼び出す場合:parseQueryString( "http://www.google.co.in/search?nomo=1&q=Quantum+physics+india&client=ms-opera-mini&channel=new&hl=en&");
あなたが得る:オブジェクト
チャネル: "new"
lient: "ms-opera-mini"
hl: "en"
q: "Quantum physics india"
url: "http://www.google.co.in/search?nomo=1"