我从 HTML 页面打开一个弹出窗口,弹出窗口与聊天服务器连接,发送可用消息,当弹出窗口关闭时它应该发送不可用消息,
问题是,当我关闭(浏览器按钮)弹出窗口时,未发送不可用消息,
我试过了,
$(window).bind("beforeunload",function(event) {
var pres = $pres({from: connection.jid, to: recipient}).c("show").t("unavailable");
connection.send(pres);
connection.disconnect();
});
也试过,
var timer = setInterval(function() {
clearInterval(timer);
if(window.closed) {
var pres = $pres({from: connection.jid, to: recipient}).c("show").t("unavailable");
connection.send(pres);
connection.disconnect();
}
}, 500);
但我有一个自己的关闭按钮,还有一个功能,它可以工作,
var onCloseChatWindow = function(){
var pres = $pres({from: connection.jid, to: recipient}).c("show").t("unavailable");
connection.send(pres);
connection.disconnect();
window.close();
}