页面刷新时如何防止调用onbeforeunload [英] How to prevent calling onbeforeunload when page refresh

查看:400
本文介绍了页面刷新时如何防止调用onbeforeunload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望阻止刷新页面时调用函数confirmExit().有可能这样做吗?

I want to prevent calling the function confirmExit() when the page is refreshed. Is it possible to do that?

<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
   $.post("test.php");
}
</script>

推荐答案

您不能.页面刷新就像导航并卸载DOM一样,因此将始终调用onbeforeunload事件.

You can't. A page refresh is like navigating away and unloading the DOM so the onbeforeunload event will always be called.

这篇关于页面刷新时如何防止调用onbeforeunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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