Close all child windows

  • Thread starter Thread starter Isabel
  • Start date Start date
I

Isabel

How can you close all child browser windows that where open by a
parent browser window? I have links on a parent (main) page that
opens the child page as a separate browser. However, I need to be
able to close all the opened child browser pages from the parent page.

Thank you for your help,

Isabel
 
Isabel,

If it's just a single window close it via it's name.

window.[window name].close()

If you have multiple child windows open use an array:

<script language="JavaScript">
<!--
openWins = new Array();
curWin = 0;

function openWin(page) { openWins[curWin++] = window.open(page,'_blank'); }

function closeAll() {
for(i=0; i<openWins.length; i++) if (openWins && !openWins.closed)
openWins.close();
}
//-->
</script>

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Hi Isabel,

1. In the JavaScript window.open() method, assign the return value to a
variable that represents the child window.
2. Make sure that no PostBacks occur in the parent window prior to
attempting to close the child windows. Otherwise, the child window variables
will be lost (they are client-side, and specific to the instance of an HTML
document that launched them)
3. Use the child window variables created in the JavaScript window.open()
method to close the child windows.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.
 
Afraid not. Once the parent window is reposted, there is no connection
between parent and children. Each child window would have to close itself.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.
 
Back
Top