http 302 重定向是可以保持 referer 的。例:在 A 頁面上提交登錄表單到 B,B 返回一個重定向頁面到 C,在 C 處理里面檢查 Referer 可知道它的來源是 A 而不是 B。
但是如果用 window.location 或 document.location 做這個跳轉就不一樣了。假如在 A 頁面上執行 window.location = B,如果是 IE 瀏覽器,會發現 B 頁面的 Referer 為空。firefox 倒是可以保持 Referer,不過在 IE 占絕大部分市場份額的中國,必須想辦法避免這個影響。
最后從網上找到這么一個解決方案:
function goTo(url) {
var a = document.createElement("a");
if(!a.click) { //only IE has this (at the moment);
window.location = url;
return
}
a.setAttribute("href", url);
a.style.display = "none";
document.body.appendChild(a)
a.click();
}
