控制window.onbeforeunload事件 [英] control window.onbeforeunload event

查看:71
本文介绍了控制window.onbeforeunload事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,我可以控制window.onbeforeunload事件,如检查用户是否决定离开页面或留在其中,我可以根据他的决定提出警告或某些功能,如果有,请告诉我

From out of curiosity can i Control window.onbeforeunload event like check if the user decided to leave the page or stay in it and can I raise an alert or some function based on his decision if yes please tell me

<script type="text/javascript">
$(window).bind("beforeunload",function(){
if(//stay on page)
alert("i want to stay on the page");
else //leave page
 alert("i want to leave the page");
});
</script>

我知道window.onbeforeunload是一个事件,它会给用户一条消息,告诉他也许你在你离开之前忘记做某事但是这个任务只是出于好奇并且谢谢你

I understand that window.onbeforeunload is an event that give the user a message to tell him that maybe you forget to do something before you leave but this quest is just out of curiosity and thank you

推荐答案

你无法得到<的结果code> onbeforeunload 。此外,即使您以某种方式设法找到获得结果的方法,您也无法提出警报。你可以运行另一个函数。

You cannot get the result of onbeforeunload. Also, even if you somehow managed to figure out a way to get the result, you wouldn't be able to raise an alert. You could probably run another function.


showModalDialog() alert() confirm() prompt()现在允许方法在 pagehide期间不执行任何操作 beforeunload 卸载活动。

The showModalDialog(), alert(), confirm() and prompt() methods are now allowed to do nothing during pagehide, beforeunload and unload events.

这篇关于控制window.onbeforeunload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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