944,131 Members | Top Members by Rank

Ad:
Aug 9th, 2007
0

Javascript: Child windows talking to each other???

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
newsteve is offline Offline
7 posts
since Aug 2007
Aug 9th, 2007
0

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

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 1:38 pm.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Frameset and setTimeout
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: starrating





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC