Executing code when the user hits the X button on the browser

I am writting an app that is going to record login times, logout times and the session data of a user of the system. This will work if the user manually logs out, but I would like it to record when the user quits if the users exits the browser (or goes to a page not in our application). Any ideas on how to accomplish this task?

Any help is appreciated.

There’s not out-of-the-box way (javascript doesn’t work, at least not for now), but you could do it with Juggernaut if it’s really important to you: http://ncavig.com/blog/?p=30#more-30

Haven’t tried it out, but it seems very nice.

Best regards

Peter De Berdt