Web Development

General discussion


Capturing Browser window close event

By pradeepbhat ·
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.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Capturing Browser window close event

by Jay Eckles In reply to Capturing Browser window ...

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

Create a framset with two frames:

<frameset rows="0,*" frameborder="0" framespacing="0">
<frame name="persistent" src="persistent.htm" noresize >
<frame name="variable" src="index.html" noresize>

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.

Collapse -

Capturing Browser window close event

by pradeepbhat In reply to Capturing Browser window ...

Point value changed by question poster.

Related Discussions

Related Forums