473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 3729
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.