Troubles closing windows

see07

Regular
Joined
Apr 16, 2004
Messages
78
Location
Mexico City
Hello:
Using JavaScript I’m opening 3 windows thus:
Win1 = window.open('2Sam7_2.htm','S71','resizable,height=350, width= 700, scrollbars=yes');
Win2 = window.open('2Sam7_2.htm','S72','resizable,height=350, width= 700, scrollbars=yes');
Win3 = window.open('2Sam7_2.htm','S73','resizable,height=350, width= 700, scrollbars=yes');

In body I’m launching: unload=”javascriptCerrarVentanas(); return false;”

My CerarVentanas function is:
Function CerrarVentanas()
{
if(Win1 && !Win1.closed)
{
Win1.window.close();
}
if(Win2 && !Win2.closed)
{
Win2.window.close();
}
if(Win3 && !Win3.closed)
{
Win3.window.close();
}
}

But when is missing Win1 doesn’t close existing windows.

Is there some guru able to help me?
I’ll appreciate your help.
A.L.
 
There could be a few problems, but one that stands out is this:

see07 said:
In body I’m launching: unload=”javascriptCerrarVentanas(); return false;”

Which should probably read:

Code:
unload=”javascript[b]:[/b]CerrarVentanas(); return false;”

...with a colon between "javascript" and your function name - otherwise the entire string literal is being interpreted as the function name. I personally do not include the "javascript:" for event handlers. I would just do:

Code:
unload=”CerrarVentanas(); return false;”

...but that's just me. You could move the "return false;" to within the body of CerrarVentanas() rather than sticking it in the event handler - but either way works fine and I'm rambling as this has no effect on your code working.

Another thing is to make sure the variables you're using to hold the references to the windows you're opening are declared outside of any functions (so that they're page-level vars). It's not clear how you're declaring them so just thought I'd mention that.

Paul
 
Last edited:
I'm showing my code, this is working fine when 3 windows are opened and I close main window, windows Win1, Win2, Win3 are closed, but when I have only Win2 or Win3 and I close main window Win2 or Win3 stay without close.

<script language="javascript">
function abre1()
{
Win1 = window.open('2Sam7_1.htm','S71','resizable,height=350, width= 700, scrollbars=yes');
}
function abre2()
{
Win2 = window.open('2Sam7_2.htm','S72','resizable,height=350, width= 700, scrollbars=yes');
}
function abre3()
{
Win3 = window.open('2Sam7_3.htm','S73','resizable,height=350, width= 700, scrollbars=yes');
}
function CerrarVentanas()
{
if((Win1) && (!Win1.closed))
{
Win1.close();
}
if((Win2) && (!Win2.closed))
{
Win2.close();
}
if((Win3) && (!Win3.closed))
{
Win3.close();
}
}

Have I some error in my code?
 
Back
Top