简体   繁体   中英

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,

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

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,

normally done using the ClientScript.RegisterStartupScript() function.

OR

You can use window.opener See Reference

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

</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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