在所有浏览器onbeforeunload无缝行为 [英] onbeforeunload seamless behavior in all browsers

查看:267
本文介绍了在所有浏览器onbeforeunload无缝行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以及球员之前,我试着写这篇文章,请放心,我在所有Chrome / Firefox和IE浏览器尝试onbeforeunload事件,它是在IE和Firefox工作正常,但在Chrome中失败了。

well guys before i tried to write this post, please be assured that i tried onbeforeunload event in all chrome / firefox and IE, it is working fine in both IE and Firefox but failing in chrome.

不过我在一个实例中注意到,我能够让Ajax调用异步设置为false,但没有工作的罚款一个跨站点Ajax调用。

I however in one instance noticed that i am able to make an ajax call async set to false, but that didnt work fine for a cross site ajax call.

给什么我​​试图做...我试图建立自动化使用jQuery测试记录和回放的JS引擎,我使用回调阿贾克斯$我的背景。

to give a background on what i am trying to do ... i am trying to build a record and playback js engine for automation testing using jquery and i am using $.ajax for callbacks.

您可以在这里找到展示

http://orgchartasp.net/jtest/ff.swf.html

我在做什么是,捕捉在客户端的所有事件,并回发到服务器onbeforeunload事件,我终于用IE和FF成功通过之前卸载打开一个模态窗口并关闭它后保存。

what i am doing is, capturing all the events on the client side and posting back to server onbeforeunload event, i finally succeeded with IE and FF by opening up a modal window on before unload and close it after save.

已经有人真的有onbeforeunload跨浏览器/跨站点,成功如果是,请帮助我。

have anyone really succeeded with onbeforeunload cross browser / cross site , if yes please help me out.

推荐答案

onbeforeunload 事件的事情是,为时已晚张贴任何东西在服务器当前窗口。引发事件,即浏览器即将加载新页面的动作,已经决定接下来要加载的页面。

The thing with the onbeforeunload event is that it's too late to post anything back to the server in the current window. The action that caused the event, i.e. that the browser is about to load a new page, has already decided what page to load next.

浏览器的确切行为时处理此事件可能会有所不同,因为它甚至没有在任何标准的HTML5之前,

The exact behaviour of the browser when handling this event may vary, as it wasn't even in any standard until HTML5.

如果您想从事件发送到任何服务器,你必须打开一个新窗口,并从张贴,或者使一个AJAX调用。这是一个虽然发射后不管,因为你不能等到任何回应。

If you want to send anything to the server from the event, you have to open a new window and post from that, or make an AJAX call. It's a fire-and-forget though, as you can't wait for any response.

我会说,你不应该依赖于 onbeforeunload 来可靠地工作,所以你不应该围绕它建立的架构。

I would say that you should not rely on the onbeforeunload to work reliably, so you shouldn't build your architecture around it.

这篇关于在所有浏览器onbeforeunload无缝行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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