我可以做一个AJAX调用时prevent window.onbeforeunload被称为 [英] Can I prevent window.onbeforeunload from being called when doing an AJAX call

查看:187
本文介绍了我可以做一个AJAX调用时prevent window.onbeforeunload被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于AJAX的网格控件。

I have an AJAX-based grid control.

我们钩到window.onbeforeunload事件来检查他们是否有未保存的数据,如果是这样一条消息,present他们你确定要离开...你有未保存的数据...。

We hook into the window.onbeforeunload event to check if they have unsaved data and if so present them with a message "Are you sure you want to navigate away...you have unsaved data...".

这一切都还是不错的。

但AJAX调用也触发window.onbeforeunload所以如果网格具有未保存的数据和我们进行AJAX调用(如删除另一个网格中的行),用户得到了你确定你要离开。 ..你有未保存的数据...消息,这是不好的。

But AJAX calls also trigger window.onbeforeunload and so if the grid has unsaved data and we make an AJAX call (such as to delete a row in another grid) the user gets the "Are you sure you want to navigate away...you have unsaved data..." message which is not good.

是否有可能燮preSS onbeforeunload事件对AJAX调用?或者是有可能检测到一个呼叫的的AJAX调用?否则,我们将不得不让黑客!

Is it possible to suppress the onbeforeunload event for AJAX calls? Or is it possible to detect that a call is an AJAX call? Otherwise we'll have to get hacking!

感谢

推荐答案

如果你想用一个超链接触发回发,有一个简单的解决方法: 而不是

If you want to trigger your postback by a hyperlink, there is a simple workaround: Instead of

< A HREF =JavaScript的:submitFunction();>提交< / A>

< A HREF =JavaScript的:;的onclick =submitFunction();>提交< / A>

只需使用此code:

< A HREF =#的onclick =submitFunction();>提交< / A>

看来,IE浏览器触发onb​​eforeunload事件,如果一个超链接的href属性的内容不是当前的页面(这锋利的字符表示)。

It seems that IE fires the onbeforeunload event if the content of the href-attribute of a hyperlink is not the current page (which the sharp character indicates).

这篇关于我可以做一个AJAX调用时prevent window.onbeforeunload被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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