取消预扣取消确认 [英] catching beforeunload confirmation canceled?

查看:111
本文介绍了取消预扣取消确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  window.onbeforunload = function( e){
return你保存一些未保存的数据,你想离开吗?
}

此提示可以通知用户,用户可以留在页面上或离开。但我想要更多地知道他是否离开,并且做他的决定的事情。我试过这个,

  window.onbeforunload = function(e){
var event = jQuery.Event(e) ;
var result = confirm('想要离开');
if(result == false){
// do sth ..
event.preventDefault();
} else {
//清理
}
}

但它失败了!它总是消失!



任何身体都可以帮助我做这个吗?

解决方案

您使用的方法(防止事件冒泡)有意无法进行,否则可能会阻止用户离开您的页面



您可以通过执行清理 onunload 来实现与您想要的相似的东西,并执行您始终执行的操作想做 onbeforeunload


I want to do some stuff when user is leaving a page, I add this code

window.onbeforunload = function (e){
   return "You save some unsaved data, Do you want to leave?";
}  

This prompt can notify the user and user can stay on the page or leave. But I want more to know whether he leaves or not, and do thing on his decision. I tried this,

window.onbeforunload = function (e){
   var event = jQuery.Event(e);
   var result = confirm('want to leave?');
   if (result ==  false){
     //do sth.. 
     event.preventDefault();
   }else{
    //do clean up
   }
} 

But it fails!! It always goes away!

Can any body help me doing this?

解决方案

The method you use (preventing bubbling of the event) is intentionally not possible, otherwise you could prevent users from leaving your page.

You can achieve something similar to what you want by doing your cleanup onunload, and do the stuff you always want to do onbeforeunload.

这篇关于取消预扣取消确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆