Closed Thread Icon

Preserved Topic: Closing window after creation Pages that link to <a href="https://ozoneasylum.com/backlink?for=18405" title="Pages that link to Preserved Topic: Closing window after creation" rel="nofollow" >Preserved Topic: Closing window after creation\

 
Author Thread
viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 05-09-2002 20:25

I have created a new window using some_var=window.open(...). This new window may be created by the visitor or not. It's an optional new window.
But I want to close this new window when the main window (the one that created it) is closed or unloaded. So, I used the event onunload to try to close it but I'm having problems.
There can have three possible situations:
1 - the main window is closed/unloaded and the new window was never created, so some_var is still undefined;
2 - the main window is closed/unloaded and the new window was already created but it has been closed prior to closing/unloading the main window. some_var is not anymore undefined and I can close the new window just by using some_var.close() on the onunload event of the main window;
3 - the main window is closed/unloaded and the new window is open; situation similar to "2", so I just use some_var.close() on the onunload event of the main window.

So, my problem is the situation "1". If I try to close some_var, I'll get an error, since some_var is undefined. But I don't know how to avoid trying to close some_var because I don't know how to detect if it is undefined or not. I have tried using if( some_var != null) but this doesn't work either.

What am I doing wrong? Is there another smarter way of doing this stuff I want to do?
TIA

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 05-09-2002 21:00
code:
function closer() {
if (some_var) { some_var.close(); }
}

window.onunload= closer;



put that in your script file and it should work as you want it to. I have only tested it in IE, but it should work in the other browsers as well.

-= Veneficuz =-
"Mundus vult decipi. Ergo decipiatur."

viol
Maniac (V) Inmate

From: Charles River
Insane since: May 2002

posted posted 05-09-2002 22:07

It worked fine in IE 6 and Netscape 6.
Thanks a lot.

« BackwardsOnwards »

Show Forum Drop Down Menu