PDA

View Full Version : close popup when leaving site


StickBoy
10-30-2002, 05:01 AM
Popup windows are annoying. However, sometimes they can be useful, for special event alerts and such.
What I would like to do is to have the popup window close itself when the user leaves the site, or even leaves the main page, if that's the only way to go.
I understand onblur, but I don't think that will work in this case. How can you tell the popup that its content is no longer valid in relation to the main window?
I don't want it on a timer, either. Just, when the main window leaves the site (or main page), the popup should close. Is it possible? How do I do it?

glenngv
10-30-2002, 06:17 AM
if this is how you opened the popup in the main window:

winpop = window.open(url,target,features);

then you can do this in the main window.

function mainUnload(){
if (winpop && !winpop.closed) winpop.close();
}

you can call it in 2 ways:

window.onunload = mainUnload;

or

<body onunload="mainUnload()">