1

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

});
harriyott
  • 10,505
  • 10
  • 64
  • 103
Gilbert V
  • 1,050
  • 5
  • 16
  • 43

2 Answers2

3

You have the onBeforeUnload event you can catch in JavaScript. See here.

Community
  • 1
  • 1
zmbq
  • 38,013
  • 14
  • 101
  • 171
  • Thank you,It seems to mostly work but safari seems to be giving me some issues. Is there another method I can use for safari besides return? – Gilbert V Sep 20 '12 at 13:47
0

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

MattTheNub
  • 111
  • 1
  • 5