View Full Version : close a popup on site exit

07-11-2003, 10:01 AM
I have a popup that plays a full song. I have it in a popup so you can listen to it and browse the site at the same time, rather than losing it as soon as you leave the page.
However, as a person who hates popups and finds that, after a while of surfing different sites, they tend to accumulate if you don't see them, I would like to have this one close when the person leaves the site.
I have external links in my site, but they all open to "target=_blank". Internal links remain in the same parent window.
Is there a way to tell the popup that the parent window is leaving the domain (yes, I have a real domain name - that must make it easier?) and to shut down, without making the user do it?

07-11-2003, 11:10 AM
My opinion is that it is improper to say "parent" when talking about popups. I think that, when open, a popup becomes an independent window so you can not close an independent window from another independent window (otherwise the rival companies would include a script to close one eachother's pages if user open both ... LOL )

I see some other solutions for your problem:

1. If you have a parent frame all over your site:

- build another frame, 1X1 px dimension, with your music in
- build an invisible DIV on parent frame, with.....

2. If you have not a parent frame:

- build a parent frame, this time your parent frame will be that 1X1 px dimension, with music
- make your popup open beneath your page (there are some scripts help u do so) then build 2 other scripts, one to focus to the popup when main page is unloaded

onunload="javascript:focus('popup.html')" or smth like that

, the second script on the popup, who will close the popup when it is focused

window.onfocus = window.close(); or smth like that

The latest ideea... I am not sure it will work, because I am affraid that the popup will be focused anyway, even for a second when open, so it will close itself right away...:-))

Has anyone other ideeas?

07-11-2003, 04:22 PM
You can have a timer running in your popup window that loops and checks every few seconds to see if the parent windows still exists.

This idea will add a lot of administrative work. Have a function execute onunload that either checks to see what domain you are navigating to or have an onclick event for every link that tells you whether the link is navigating away from your site or not.

07-11-2003, 06:20 PM
is it possible, arnyinc? How could a function client-side written in a page to check if another independent page is open or not?

07-11-2003, 07:33 PM
A parent can refer to a popup that it spawned and vice versa. There is a bug in IE with window.opener that will cause problems though.


Here is a link to something that might work, but it is untested.


07-11-2003, 07:48 PM
sounds logical... but... it might be a silly question, yet ...where do I specify the child window's name? Where to insert name="" ?

07-11-2003, 08:21 PM
Originally posted by Kor
sounds logical... but... it might be a silly question, yet ...where do I specify the child window's name? Where to insert name="" ?

Create the popup like this:

var popwin = window.open('your_page.htm', 'mywin', any other variables);

I don't recall if you would refer to it as mywin or popwin in this situation, but I believe mywin is correct.

You can then refer back to the parent/opening window as window.opener.

07-12-2003, 11:22 AM
Sorry for insist... yet I don't see...

var popwin = window.open('your_page.htm', 'mywin', any other variables);

that means I am looking for a window called "mywin" by the name. Ok till now. But were do I write in the inner popup something like name="mywin", to be alble to refere that popup, an not another... This is my quest...:confused: