472,789 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

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 3686
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jrefactors | last post by:
>From the main page, there are lots of links to open new window. i.e. <a href="#" onClick="window.open('child1.html')">Open Child Window</a> If I close the main page, I want to close all child...
2
by: Guy Babbitt | last post by:
I have an MDI application that starts an instance of a child form at application start. I have an event handler on a combo box checking for the selected value to change. When the select value...
0
by: Prisy | last post by:
I am working on a web application. When i log out of the parent window i want all the child windows that are open to close. I picked one of the child windows and tried the code shown below to...
2
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open....
0
by: Tom | last post by:
Let's say I have an MDI parent that has 5 open child windows in it. Now let's say that I have a function in the MDI parent that attempts to close all the child windows. It's starts running, closing...
3
by: VhD50 | last post by:
Hello all, Is there a way that I can close all the mdi child windows from the mdi parent's menu item? For example, on the MDI parent from, I have a MainMenu with "File" and "Close All" menu items....
6
zybernau
by: zybernau | last post by:
hi, all in javascript i need to close all the child windows that i have opened through a parent window scenario: * here i will be having as many as child window opened and name given to...
1
by: michal.podlewski | last post by:
Hi All, I have a problem with a simple (as I thought till now) thing: I want to make a link in a child-window which would change site in the parent-window and along with closing child window. The...
3
by: =?Utf-8?B?RGF2ZVA=?= | last post by:
I've got a situation in a VB 2003 Windows application with an MDI form and a child form. In certain situations, when the child is closed by the user, I also want to close the MDI parent. Is there...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.