AJAX and onbeforeunload event

AJAX and onbeforeunload event

本文关键字:event onbeforeunload and AJAX      更新时间:2023-09-26

>我有一个aspx页面。在页面上,我有一个javascript函数

window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page.  If you have made any changes to the fields      without clicking the Submit button, your changes will be lost.  Are you sure you want to exit   this page?";
}   

这将在用户离开页面时执行。但是,它也在部分页面回发上执行。如何检查这是否是部分页面回发并忽略它?

我可以防止在执行 AJAX 调用时调用 window.onbeforeunload

查看您正在执行的操作是否执行以下任何操作:

在卸载之前事件

若要调用此事件,请执行下列操作之一:

  • 关闭当前窗口。
  • 通过输入新地址或选择收藏夹导航到其他位置。
  • 单击引用另一个文档的锚点。
  • 调用 anchor.click 方法。
  • 调用 document.write 方法。
  • 调用 document.close 方法。
  • 调用 window.close 方法。
  • 调用 window.navigate 或 NavigateAndFind 方法。
  • 调用 location.replace 方法。
  • 调用 location.reload 方法。
  • 为 location.href 属性指定一个新值。
  • 将表单提交到中指定的地址通过 INPUT type=submit 控件的 ACTION 属性,或调用表单提交方法。
  • 调用 window.open 方法,提供窗口名称的可能值_self。
  • 调用 document.open 方法。
  • 单击"后退"、"前进"、"刷新"或"主页"按钮。