Close all child windows

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
 
S

S. Justin Gengo

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
 
K

Kevin Spencer

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.
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top