Discussion Locked

Capturing Browser window close event

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I want to display a message using JavaScript when the user closes browser window. I can't use onUnLoad becaue this fucntion will be called when REfresh button is clicked.

2 replies

by jay eckles

I have searched for the same answer myself. The best I have found is to do the following:

Create a framset with two frames:

As you can see, one frame is totally hidden. In "persistent.htm", put your code in the onUnLoad event. Make the src of the other (visible) frame your normal page. The experience is invisible to the user - he or she has no idea there are any frames, and the only way the onUnLoad event of persistent.htm fires is if the user either closes the browser or enters a new location in the "Address" field in the browser.

If you want your message to pop up whenever the user leaves index.htm (instead of the whole site), then use a baseref with target=top.

That is the best solution I've come across.

This discussion is closed to new replies.