User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 397,851 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,332 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1584 | Replies: 1
Reply
Join Date: Aug 2007
Posts: 4
Reputation: newsteve is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
newsteve newsteve is offline Offline
Newbie Poster

Javascript: Child windows talking to each other???

  #1  
Aug 9th, 2007
Hi there,

Im trying to design a fun page where a after an onclick on the parent page, several small child windows are opened. Upon clicking the content of any of those windows, I want all of the child windows to close. I can get self.close() to close the clicked window, but I cannot communicate with the other child windows, even if I reference them by their name, ie winName.close()... are there special rules for doing this?
Essentially, Im wondering if child windows can talk to each other, there must be a way for that to happen...?

A miniaturized version of what I am trying to do can be seen here:
http://stevenewberry.com/experimental/randombirds1.html
(click the red square!)

Thanks for any insight you may have...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,806
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 338
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Javascript: Child windows talking to each other???

  #2  
Aug 9th, 2007
You need to enter the reference to the newly created pages in an array which is kept in the main page and use that array to loop through the window references and close them.

Something like this:

 Main.html

<html>
<head>
    <script>
    var wnd = new Array();
     function openit(id)
    {
        if(!wnd[id] || wnd[id].closed)
            wnd[id] = window.open("Child.html");    
        else
            wnd[id].focus();
    }
    
    function closeEverything()
    {
        for(var i = 0; i < wnd.length; ++i)
            wnd[i].close();
    }
    </script>
</head>
<body>
    <form>
        <input type="button" value="Open1" onclick="openit(0);" /><br/>
        <input type="button" value="Open2" onclick="openit(1);" /><br/>
        <input type="button" value="Open3" onclick="openit(2);" /><br/>
    </form>
</body>
</html>

 Child.html

<html>
<head>
    <script>
    function closeAll()
    {
        window.opener.closeEverything();
    }
    </script>
</head>
<body>
    <form>
        <input type="button" value="Close Me" onclick="window.close();" /><br/><br /><br />
        <input type="button" value="Close all children" onclick="closeAll();" /><br/>
</form>
</body>
</html>
Last edited by ~s.o.s~ : Aug 9th, 2007 at 12:38 pm.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 8:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC