Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

OnUnload event hadler during browser refresh



2:49 pm on Feb 18, 2001 (gmt 0)

Inactive Member
Account Expired


I have a client that wants a popup window
to load when a user leaves a certain page.

*Yes, I know this is bad etiquette. That's
between him and his customers.*

I haven't used the onUnload handler before
and it seems to be invoked when I manually
refresh the browser. I may be picky, but
I don't like it.

Has anyone found a way to short-circuit
the handler if a user manually refreshes
the page?
Basically, I don't want it to happen.

Thank you very much
Eric Reynolds

9:21 pm on Feb 18, 2001 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
votes: 0

Hello EReynolds, and welcome to WebmasterWorld.

Your question sent me digging through reference books and doing some online research, but the situation looks unresolvable to me because of two things --

1) a refresh always triggers an onUnload event
2) there's no way that JavaScript on one page can automatically find out what page will load next. That would introduce outrageous security problems.

One solution (that really isn't a solution at all) might be to first use the onUnload event to trigger a confirm box that asks if the visitor really intends to leave the page.

Of course, then you've popped up something anyway, but if you really want to save the pop-up information until a true page exit, at least this technique would do that.


10:51 am on Apr 11, 2001 (gmt 0)

Inactive Member
Account Expired


I have a similar situation. The only difference is that I don't mind if the browser refresh triggers the OnUnload.
I want to be informed of internal server errors, so I'd like to submit the contents of a form on my Error 500 page to Matt Wright's formmail script whenever the user leaves. It should be up to the user if he fills the form out (comments, etc.) Even if blank, however, I would at least be notified of a problem.

Now I've only gotten the procedure to work upon a browser refresh, but unfortunately not on a normal unload like the back button or a manually typed URL.

Any suggestions?