470,586 Members | 1,296 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,586 developers. It's quick & easy.

Close all child windows

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
Nov 17 '05 #1
3 3551
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[i] && !openWins[i].closed)
openWins[i].close();
}
//-->
</script>

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Isabel" <ie****@hotmail.com> wrote in message
news:1f**************************@posting.google.c om...
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

Nov 17 '05 #2
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.

"Isabel" <ie****@hotmail.com> wrote in message
news:1f**************************@posting.google.c om...
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

Nov 17 '05 #3
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.

"Isabel" <ie****@hotmail.com> wrote in message
news:1f**************************@posting.google.c om...
Thanks Kevin. One followup question. I do need to perform a postback
on my parent form. Is there anyway to not lose the references to the
named child windows? Is there anyway to save them and have Javascript
then be able to reference them to close the windows?

Thank you for your assistance.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message

news:<ec**************@tk2msftngp13.phx.gbl>...
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.

"Isabel" <ie****@hotmail.com> wrote in message
news:1f**************************@posting.google.c om...
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

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jrefactors | last post: by
2 posts views Thread by Guy Babbitt | last post: by
1 post views Thread by michal.podlewski | last post: by
3 posts views Thread by =?Utf-8?B?RGF2ZVA=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.