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

    history.navigationMode = 'compatible';

//Sends the information to the file. 
function ReturnMessage()

//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. See here.


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)


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.