I was struggling with that problem a while ago..there doesnt seem to be any sure-shot way..
I remember seeing some javascript code on the net that does this -
1. on unLoad, open a window, using javascript
2. In that window, check the opener property to see if the original window is still open.
If it is open, means the user hasnt closed the browser, something else triggered the onUnload event, do nothing.
If it is closed, call the servlet code to do whatever u want to do
3. Close the new window.
I never tried it throughly, you might want to think along those lines.
and you may find some ideas in this discussion
discussion