This is a hack but it seems to work for me. It might be IE specific as well. I code for an IE only environment.
Edited to add that my unloadFunction opens a popup window that kills the user's session. You can't do anything on the page that was closed itself. 'cause it's closed already! ;)