简体   繁体   English

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

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

Hello I am looking for information on the close tab (not browser) event if there is one in java for a applet. 您好我正在寻找关闭选项卡(而不是浏览器)事件的信息,如果在Java中有一个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? 这是可能的,还是与Java或Javascript有关?

UPDATE: okay with the information you guys pointed me into i was able to get information on a simple enough javascript. 更新:好的,你们指出我的信息,我能够获得一个简单的javascript信息。 Now it is working fine in IE , Chrome and Firefox but for some reason Safari 5.1.7 isn't liking the code. 现在它在IE,Chrome和Firefox中运行良好,但出于某些原因,Safari 5.1.7并不喜欢这些代码。 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. 您可以使用JavaScript捕获onBeforeUnload事件。 See here . 看到这里

Use window.onbeforeunload 使用window.onbeforeunload

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

Note that it will also end in Are you sure you want to leave this page (or are you sure you want to reload this page if you are reloading) 请注意,它也将结束您确定要离开此页面 (或者如果要重新加载,确定要重新加载此页面

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

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