Javascript: Child windows talking to each other???

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2007
Posts: 7
Reputation: newsteve is an unknown quantity at this point 
Solved Threads: 0
newsteve newsteve is offline Offline
Newbie Poster

Javascript: Child windows talking to each other???

 
0
  #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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,610
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #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 1:38 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC