A bit of background before my next question/thought about this....
I need to track when the user leaves the webpage. I am setting a 2 minute timer to go off when the onbeforeunload event is called. After the 2 minutes, the user's session is invalidated.
What I'm trying to achieve is to cancel the timer if the user clicks "Cancel" on the onbeforeunload event. The earlier code posted does indeed allow this to happen with IE because IE waits for me to answer the OK - Cancel question before firing the alert message.
As the notes from Kravvitz's code say, and as I've found myself, Firefox doesn't wait, so I can't go off and cancel the timer quite yet because the user hasn't made a choice. Waiting for one second also will not likely give the user enough time to answer. I can increase the setTimout to something like 10 or 20 seconds, and then reset the timer, but then I would have to hope that the user actually makes the choice before that time is up.
I would obviously much rather implement it so the timer is only cancelled when the user presses "Cancel". If there were a way to check to see if the prompt was still open, then I could extend the timer. If the prompt was closed, I would know the user pressed "Cancel". I don't know of a way to do this, however.
Thanks for the help.