繁体   English   中英

如何在浏览器选项卡中检测到关闭?

[英]How can I detect a close in the browser tab?

您好我正在寻找关闭选项卡(而不是浏览器)事件的信息,如果在Java中有一个applet。 我想知道是否有事件或检查方法来检查。 我想抓住事件并制作一个小弹出框,说明你的会话将会过期或者其他类似的东西。 这是可能的,还是与Java或Javascript有关?

更新:好的,你们指出我的信息,我能够获得一个简单的javascript信息。 现在它在IE,Chrome和Firefox中运行良好,但出于某些原因,Safari 5.1.7并不喜欢这些代码。 不知道为什么。 这是代码,如果它有帮助。

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

});

您可以使用JavaScript捕获onBeforeUnload事件。 看到这里

使用window.onbeforeunload

window.onbeforeunload = function () {
    return "Are you sure you want to exit?";
};

请注意,它也将结束您确定要离开此页面 (或者如果要重新加载,确定要重新加载此页面

暂无
暂无

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

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