Chrome中的window.onbeforeunload:最近的修复是什么? [英] window.onbeforeunload in Chrome: what is the most recent fix?
问题描述
显然,window.onbeforeunload已经遇到了Chrome的问题,正如我从遇到的所有问题中看到的那样。最近的工作是什么?
Obviously, window.onbeforeunload has encountered its fair share of problems with Chrome as I've seen from all the problems I've encountered. What's the most recent work around?
我唯一接近工作的是这个:
window.onbeforeunload = function () { return "alert" };
但是,如果我用警报(blah)代替返回alert,我会得到Chrome中没有任何内容。
However, if I substitute return "alert" with something like alert("blah"), I get nothing from Chrome.
我在这个问题谷歌故意阻止这一点。对他们有好处......但如果有人关闭窗口我想要进行AJAX调用怎么办?在我的情况下,我想知道有人离开我的网站上的聊天室,由窗口关闭发出信号。
I saw in this question that Google purposefully blocks this. Good for them... but what if I want to make an AJAX call when someone closes the window? In my case, I want to know when someone has left the chatroom on my website, signalled by the window closing.
我想知道是否有办法让
(a):修复window.onbeforeunload调用,以便我可以将AJAX放在那里
或
(b):获取确定Chrome窗口已关闭的其他方法
I want to know if there's a way to either
(a): fix the window.onbeforeunload call so that I can put AJAX in there
or
(b): get some other way of determining that a window has closed in Chrome
推荐答案
答案:
$(window).on('beforeunload', function() {
var x =logout();
return x;
});
function logout(){
jQuery.ajax({
});
return 1+3;
}
有点混搭,但它对我有用。 1 + 3确保正在调用注销功能(当你试图离开时,如果它在弹出窗口上成功,你会看到4)。
A little mix and match, but it worked for me. The 1+3 makes sure that the logout function is being called (you'll see 4 if it's successful on the popup when you try to leave).
这篇关于Chrome中的window.onbeforeunload:最近的修复是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!