如何检测浏览器选项卡中关闭? [英] How can I detect a close in the browser tab?
问题描述
您好,我寻找的密切片(未浏览器)事件上的信息,如果有一个在java中的小程序。我想知道如果有该或方法来检查的方式来检查该事件。我想只捕获事件,并做出一点弹出对话框,提示您的会话将到期或类似的规定。这是可能在所有或使用Java或Javascript?
点更新:与你没关系家伙指着我进,我是能够得到一个足够简单的JavaScript信息的信息。现在它在IE,Chrome和火狐工作正常,但由于某些原因的Safari 5.1.7不顺心的code。不知道为什么。这里是code。如果它帮助。
的jQuery(函数(){
变种hiddenBtn =的document.getElementById(javaform:browserCloseSubmit);尝试{
opera.setOverrideHistoryNavigationMode('兼容');
history.navigationMode ='兼容';
}赶上(E){}//发送信息到javaBean.java文件。
功能ReturnMessage()
{
返回hiddenBtn.click();
}//取消绑定功能
功能UnBindWindow()
{
jQuery的(窗口).unbind('beforeunload',ReturnMessage);
}//绑定退出消息对话
jQuery的(窗口).bind('beforeunload',ReturnMessage);});
您有 onBeforeUnload
事件时,可以在JavaScript中赶。请参见 href=\"http://stackoverflow.com/questions/1704533/intercept-page-exit-event\">。
Hello I am looking for information on the close tab (not browser) event if there is one in java for a applet. I am wondering if there is an event for that or a way to check a way to check for that. I would like to just capture the event and make a little popup box , stating Your session will expire or something along those lines. Is that possible at all or to a point with java or Javascript?
UPDATE: okay with the information you guys pointed me into i was able to get information on a simple enough javascript. Now it is working fine in IE , Chrome and Firefox but for some reason Safari 5.1.7 isn't liking the code. Not sure why. Here is the code if it helps.
jQuery(function() {
var hiddenBtn = document.getElementById("javaform:browserCloseSubmit");
try{
opera.setOverrideHistoryNavigationMode('compatible');
history.navigationMode = 'compatible';
}catch(e){}
//Sends the information to the javaBean.java file.
function ReturnMessage()
{
return hiddenBtn.click();
}
//UnBind Function
function UnBindWindow()
{
jQuery(window).unbind('beforeunload', ReturnMessage);
}
//Bind Exit Message Dialogue
jQuery(window).bind('beforeunload', ReturnMessage);
});
You have the onBeforeUnload
event you can catch in JavaScript. See here.
这篇关于如何检测浏览器选项卡中关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!