jQuery绑定beforeunload - 不使用IE 9 [英] jQuery bind beforeunload - not working with IE 9

查看:46
本文介绍了jQuery绑定beforeunload - 不使用IE 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码,我希望在页面关闭时触发(基本上,向服务器发送'断开'的消息。执行应该足够快,我不必取消并重新启动事件。 ,它在Chrome,Firefox和Safari中完美运行,但在关闭选项卡时不在IE9中。如果我导航到IE9中的另一个页面,我的事件会触发。如果我​​关闭选项卡,它不会。
我尝试过以下内容绑定我的代码:

I have a piece of code i want fired when the page closes (basically, send a 'disconnected' message to the server. The execution should be fast enough for me not to have to cancel and restart the event. Further to that, it works perfectly in Chrome, Firefox and Safari, but not in IE9 on closing the tab. If i navigate to another page in IE9, my event fires. If i close the tab, it doesn't. I tried the following to bind my code:

jQuery(window).bind("beforeunload", function() { DoSomeWork(); });

我也尝试用$替换jQuery:

i also tried replacing jQuery with $ like so:

$(window).bind("beforeunload", function() { DoSomeWork(); });

仍可在Chrome中使用,但在IE中无效。
有什么建议吗?

Still works in Chrome, but does not work in IE. Any suggestions?

我使用的是jquery 1.9.1分钟(压缩生产版本)。

I am using jquery 1.9.1 min (compressed production version).

推荐答案

试试这个

onbeforeunload = function() {
     return "Are you sure";
}

测试 Chrome版本26.0.1410.64 m Firefox版本20.0.1 Internet Explorer版本9.0

FIDDLE

这篇关于jQuery绑定beforeunload - 不使用IE 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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