簡體   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