[英]How to stop page from redirecting without event in Javascript or jQuery?
[英]How to stop the page from redirecting to another page without the user action (StopPropogation) and window.oneforeunload event?
function confirmExit(e) {
var f = FormChanges(); //checking whether page has been modified or not
if (f.length > 0){
if (submitForm == false) {
if(!e) var e = window.event;
//e.cancelBubble for IE and it does work
e.cancelBubble = true;
e.returnValue = "You have made updates to this page which have not been saved.";
//e.stopPropagation for Firefox doesn't work.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
}
setTimeout("enableBeforeUnloadHandler()", "100");
}
} //ignore this
window.onbeforeunload=confirmExit;
function enableBeforeUnloadHandler()
{
window.onbeforeunload=confirmExit;
}
當用戶想轉到其他頁面而不在當前頁面提交表單時,它會提示是否離開該頁面?
但是問題是,它可以在幾秒鍾內重定向到另一個頁面,而根本不等待用戶操作,我該如何解決? (我無法在Firefox中工作,在IE中也可以正常工作)
可能是這樣的:
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}
您實際上需要返回true
(更改頁面)或false
(停留在頁面上)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.