1

您好我正在寻找有关关闭选项卡(不是浏览器)事件的信息,如果在 java 中有一个用于小程序的事件。我想知道是否有一个事件或一种方法来检查一种方法来检查它。我只想捕获该事件并制作一个小弹出框,说明您的会话将过期或类似的内容。这完全有可能还是使用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);

});
4

2 回答 2

3

您拥有onBeforeUnload可以在 JavaScript 中捕获的事件。见这里

于 2012-09-18T21:08:52.720 回答
0

采用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)

于 2016-03-16T21:03:26.230 回答