[Javascript] Closing multiple child windows

Peter Brunone peter at brunone.com
Tue Dec 6 17:04:11 CST 2005


Hi Liam,
 
    If you want to close a child window, you need to maintain a
reference to it.  In this case you might consider making each window an
element of the childWindow array, i.e.
 
// Global variables (outside your function)
var childWin = new Array();
var iWin = 0;
 
//Every time you open a new window:
childWin[iWin] = window.open('flash/' + sFileName, '', 'top=' + iTop +
', left=' + iLeft + ',
width=740,height=450,scrollbars=no,menubar=no,toolbar=no,resizable=no,st
atus=no');
iWin++;
 
    Then to close them, you'd just have to loop back through the windows
to close them:
 
for(iWin=0;iWin<childWin.length;iWin++) {
    if (childWin[iWin] != null && !childWin[iWin].closed)
childWin[iWin].close();
    }
 
 
Hope that helps...
 
Peter

-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Liam Rice


I have a page in which a user is able to open zero to many child
windows.  I need to be able to close all of these child windows within a
single function.  Anybody ever created something like this before?  I've
got no problem closing just a single child, but when I have more than
one open is where I'm having issues.  Any help would be appreciated,
thanks
 
var childWin = null;
 
childWin = window.open('flash/' + sFileName, '', 'top=' + iTop + ',
left=' + iLeft + ',
width=740,height=450,scrollbars=no,menubar=no,toolbar=no,resizable=no,st
atus=no');
 
function closeChild() {
  if (confirm('This will close any courses you have open.  Do you wish
to continue?')) {
    if (childWin != null && !childWin.closed) childWin.close();
  }
}
Liam David Edwin Rice

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20051206/b24908bd/attachment.htm>


More information about the Javascript mailing list