I would like to execute certain code only when a user leaves a window by closing the navigator. I have been looking at some events such as onUnload, but that does not do what i want since it executes every time the user leaves the window (going to another page and such).