帶著窗口.位置對象。這段代碼給了你一個(gè)沒有問號的GET。
window.location.search.substr(1)
從您的示例中,它將返回。returnurl=%2Fadmin
編輯:我冒昧地改變了QWERTY的回答,也就是真的很好,正如他指出的,我完全按照“行動(dòng)綱領(lǐng)”的要求行事:
function findGetParameter(parameterName) {
var result = null,
tmp = [];
location.search .substr(1)
.split("&")
.forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;}
我從他的代碼中刪除了重復(fù)的函數(shù)執(zhí)行,將它替換為一個(gè)變量(Tmp),并且我還添加了decodeURIComponent
就像OP問的那樣。我不確定這是否是安全問題。
或者使用普通的for循環(huán),即使在IE8中也能工作:
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;}