homepage Welcome to WebmasterWorld Guest from 54.234.225.23
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Closing All child window in javascript
how to close all child window when log off button is clicked
visu




msg:1480834
 3:57 am on May 25, 2006 (gmt 0)

how to close all child windows and parent window when log off button is clicked in a page which is in either child window or parent window using javascript.any one help me in this regard?

 

Dijkgraaf




msg:1480835
 6:41 am on May 28, 2006 (gmt 0)

The child window can certainly use the window.opener to find the parent window and attempt to close that.

However it wouldn't know about the other child windows, and so you would probably want to put a onunload trigger on the parent window to try and close all the child windows.

You would have to keep a reference in the parent window of any child windows opened to achieve this.

For example see
[faqts.com...]

<INPUT TYPE=button onClick="Child=window.open
('http://www.google.com','Child')" VALUE="Open">

<INPUT TYPE=button onClick="Child.close()" VALUE="Close">

Where they assign Child, a reference to the window being opened.

texmex




msg:1480836
 8:13 pm on May 28, 2006 (gmt 0)

How about this idea. Somewhere at the top of your script in your main document you include a line:var children=Array();

Now whenever you want to open a new child window make sure you use a line similar to:

children[children.length]=etc..

You can then have one function such as:

function closeAllChildren()
{
for(var n=0;n<children.length;n++)
{children[n].close();
}
//Oh, and close self!
window.close();
}

Each child document just needs a button to call this function as follows.

<input type="button" onclick="window.opener.closeAllChildren()">

visu




msg:1480837
 3:50 am on May 29, 2006 (gmt 0)

thanks for ur suggesstions i'll try this

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved