AJAX和onbeforeunload事件 [英] AJAX and onbeforeunload event

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

问题描述

我有一个aspx页面。在网页上我有一个JavaScript函数

I have an aspx page. On the page I have a javascript function

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?";

}   

这执行用户离开该页面后。然而,它也执行的部分页面回发。我该如何检查,看看这是否是一个局部页面回发,而忽略它?

This executes when the user leaves the page. However it also executes on the partial page postbacks. How do I check to see if this is a partial page postback and ignore it?

推荐答案

<一个href="http://stackoverflow.com/questions/537702/can-i-$p$pvent-window-onbeforeunload-from-being-called-when-doing-an-ajax-call">Can我做一个AJAX调用

请参阅如果你正在做的动作做任何如下:

See if the action you are doing does any of the following:

onbeforeunload事件

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

To invoke this event, do one of the following:

  • 关闭当前窗口。
  • 将进入一个新的地址,或者选择最喜欢的导航到另一个位置。
  • 单击指向另一个文档中的锚。
  • 调用anchor.click方法。
  • 调用的document.write方法。
  • 调用document.close方法。
  • 调用window.close方法。
  • 调用window.navigate或NavigateAndFind方法。
  • 调用location.replace方法。
  • 调用location.reload方法。
  • 指定为location.href属性的新值。
  • 在提交表单到指定的地址 通过输入型action属性=提交控件,或调用 form.submit方法。
  • 调用window.open方法,提供 可能值_self的窗口名称。
  • 调用document.open方法。
  • 单击后退,前进,刷新,或主页按钮。
  • Close the current window.
  • Navigate to another location by entering a new address or selecting a Favorite.
  • Click an anchor that refers to another document.
  • Invoke the anchor.click method.
  • Invoke the document.write method.
  • Invoke the document.close method.
  • Invoke the window.close method.
  • Invoke the window.navigate or NavigateAndFind method.
  • Invoke the location.replace method.
  • Invoke the location.reload method.
  • Specify a new value for the location.href property.
  • Submit a form to the address specified in the ACTION attribute via the INPUT type=submit control, or invoke the form.submit method.
  • Invoke the window.open method, providing the possible value _self for the window name.
  • Invoke the document.open method.
  • Click the Back, Forward, Refresh, or Home button.

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

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