简体   繁体   English

关闭弹出窗口时,没有事件发生

[英]Upon Closing pop-up no event occurs

Im opening a pop-up window from a HTML page, the pop-up window connects with a chat server, send a available message, and it should send a unavailable message when the pop-up closes, 我从HTML页面打开了一个弹出窗口,该弹出窗口与聊天服务器连接,发送了一条可用消息,并且当该弹出窗口关闭时,它应该发送一条不可用消息,

The problem is, When i close(browser button) the pop-window, The unavailable message does not sent, 问题是,当我关闭(浏览器按钮)弹出窗口时,不可用消息未发送,

I tried, $(window).bind("beforeunload",function(event) { var pres = $pres({from: connection.jid, to: recipient}).c("show").t("unavailable"); connection.send(pres); connection.disconnect(); }); 我试过了, $(window).bind("beforeunload",function(event) { var pres = $pres({from: connection.jid, to: recipient}).c("show").t("unavailable"); connection.send(pres); connection.disconnect(); });

also tried, 也尝试过

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);

But I have one close button of my own, and a function for it, it works, 但是我有一个自己的关闭按钮,并且有一个功能可以正常工作,

var onCloseChatWindow = function(){
var pres = $pres({from: connection.jid, to: recipient}).c("show").t("unavailable");
connection.send(pres);
connection.disconnect();
window.close();
}

You need to Postback 您需要回发

A postback is the process of re-loading a page, so if you want the page to close after the postback then you need to set your window.close() javascript to run with the browser's onload event during that postback, 回发是重新加载页面的过程,因此,如果您希望页面在回发后关闭,则需要设置window.close()javascript以在该回发期间与浏览器的onload事件一起运行,

normally done using the ClientScript.RegisterStartupScript() function. 通常使用ClientScript.RegisterStartupScript()函数完成。

OR 要么

You can use window.opener See Reference 您可以使用window.opener 参见参考

<body onclose="window.opener.somefunction('value');window.close();">

</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM