我將如何去重寫/捕捉JavaScript重定向?捕捉/重寫Javascript重定向
例如:
window.location.href="http://example.com";
值 「http://example.com」 會被抓住,也許改變。
我將如何去重寫/捕捉JavaScript重定向?捕捉/重寫Javascript重定向
例如:
window.location.href="http://example.com";
值 「http://example.com」 會被抓住,也許改變。
AFAIK你可以捕捉這個事件,但你不能改變目標網址。您只能提示用戶是否要取消重定向。爲此,您可以訂閱before unload event:
window.onbeforeunload = function (e) {
var e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Are you sure you want to leave the site?';
}
// For Safari
return 'Are you sure you want to leave the site?';
};
找到使用這一切代碼:
window.location.href="http://example.com";
它改成這樣:
openURL("http://example.com");
然後,實現這個功能,你可以控制重定向,但是你想:
function openURL(url) {
// examine url and decide if you want to modify it
window.location = url;
}
這可能有幫助嗎? http://stackoverflow.com/questions/3522090/event-when-window-location-href-changes – Asken