How to capture closing of browser?

I want to insert some data (session variables) in a database table when user closes the browser and comes out of the application. How can I do it? Can anyone please show me the sample code?
[196 byte] By [anirbanchandaa] at [2007-9-19]
# 1
There are some javascript tricks that allegedly can be run when the browser window closes. Whether these can notify your application reliably I do not know. I suggest you redo your design so that closing the browser is not your signoff signal.
DrClapa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2
I require to capture the closing of a browser. How to do it?
anirbanchandaa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3
> I require to capture the closing of a browser. How to> do it?It has been discussed many a times in this forum and nobody has come out with a proper solution. have a look at, http://forum.java.sun.com/thread.jsp?forum=33&thread=220036Sudha
sudha_mpa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
How about a http-equiv refresh tag that sends a heartbeat from a hidden frame?
johnmillingtona at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5

I'm sure you can use a javascript function to capture the UnLoad event and then call a page in your server, try this:

<script language="javascript">

<!--

function logOff() {

newWind = window.open ("LogOff_Page.jsp","Mywindow","HEIGHT=100,WIDTH=350")

// this will pop-up a small window, you may decide the size though

}

}

//-->

</script>

<body onUnload="logOff()")

><-- your page here -->

</body>

Ronel

ronelalfonsoa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6

if you don't need additional information from the client browser and just want to store data that is allready in the server side, you may choose the notification mechanism that the session object implements - just after the given time of inactivity the session object gets destroyed and at that time the notification handler is calles. just use that mechanism, it's very easy and secure!

joshmana at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...