close all child windows when close the main window

Discussion in 'HTML' started by jrefactors@hotmail.com, Jan 15, 2005.

  1. Guest

    >From the main page, there are lots of links to open new window.
    i.e. <a href="#" onClick="window.open('child1.html')">Open Child
    Window</a>

    If I close the main page, I want to close all child windows also. That
    means I
    need to keep track all handles of the child windows whenever I open a
    new
    window. Correct? any suggestions on the approach?
    Please advise. thanks!!
    , Jan 15, 2005
    #1
    1. Advertising

  2. porneL Guest


    > If I close the main page, I want to close all child windows also. That
    > means I need to keep track all handles of the child windows whenever I
    > open a
    > new window.


    That won't work if user browses in main window.

    IMO the best way is to simply add 'dependent=yes' to popup window
    attributes.
    Doesn't work everywhere, but when works - it works :)

    BTW: never use href="#", put real address there and use return false in
    onclick.
    This will improve search engine visibility, ensure that windows open in new
    window, links can be copied/bookmarked, etc.

    --
    * html {redirect-to: url(http://browsehappy.pl);}
    porneL, Jan 15, 2005
    #2
    1. Advertising

  3. Chung Leong Guest

    [OT] Re: close all child windows when close the main window

    <> wrote in message
    news:...
    > >From the main page, there are lots of links to open new window.

    > i.e. <a href="#" onClick="window.open('child1.html')">Open Child
    > Window</a>
    >
    > If I close the main page, I want to close all child windows also. That
    > means I
    > need to keep track all handles of the child windows whenever I open a
    > new
    > window. Correct? any suggestions on the approach?
    > Please advise. thanks!!
    >


    Yes. Wouldn't be hard if you define a Javascript function for opening
    windows and save the handles into an array.

    Or you could use the ShowModelessDialog() function. Modless dialog boxes
    stay in front of their parent window and automatically would close when the
    parent closes.
    Chung Leong, Jan 16, 2005
    #3
  4. Randy Webb Guest

    Re: [OT] Re: close all child windows when close the main window

    Chung Leong wrote:
    > <> wrote in message
    > news:...
    >
    >>>From the main page, there are lots of links to open new window.

    >>i.e. <a href="#" onClick="window.open('child1.html')">Open Child
    >>Window</a>
    >>
    >>If I close the main page, I want to close all child windows also. That
    >>means I
    >>need to keep track all handles of the child windows whenever I open a
    >>new
    >>window. Correct? any suggestions on the approach?
    >>Please advise. thanks!!
    >>

    >
    >
    > Yes. Wouldn't be hard if you define a Javascript function for opening
    > windows and save the handles into an array.
    >
    > Or you could use the ShowModelessDialog() function. Modless dialog boxes
    > stay in front of their parent window and automatically would close when the
    > parent closes.


    Modeless Dialogs are also IE-only.

    I might be able to understand the OT if this were not posted to
    comp.lang.javascript


    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Jan 16, 2005
    #4
  5. Chung Leong Guest

    Re: [OT] Re: close all child windows when close the main window

    "Randy Webb" <> wrote in message
    news:...
    > Chung Leong wrote:
    > > <> wrote in message
    > > news:...
    > >
    > >>>From the main page, there are lots of links to open new window.
    > >>i.e. <a href="#" onClick="window.open('child1.html')">Open Child
    > >>Window</a>
    > >>
    > >>If I close the main page, I want to close all child windows also. That
    > >>means I
    > >>need to keep track all handles of the child windows whenever I open a
    > >>new
    > >>window. Correct? any suggestions on the approach?
    > >>Please advise. thanks!!
    > >>

    > >
    > >
    > > Yes. Wouldn't be hard if you define a Javascript function for opening
    > > windows and save the handles into an array.
    > >
    > > Or you could use the ShowModelessDialog() function. Modless dialog boxes
    > > stay in front of their parent window and automatically would close when

    the
    > > parent closes.

    >
    > Modeless Dialogs are also IE-only.
    >
    > I might be able to understand the OT if this were not posted to
    > comp.lang.javascript


    Oops. Why did the OP cross post into comp.lang.php?
    Chung Leong, Jan 16, 2005
    #5
  6. sateeshranga

    Joined:
    Aug 7, 2008
    Messages:
    2
    close all child windows

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

    <strong class="highlight">Child</strong>.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>
    sateeshranga, Aug 7, 2008
    #6
  7. sateeshranga

    Joined:
    Aug 7, 2008
    Messages:
    2
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>untitled</title>
    <style type="text/css">

    input {
    width: 80px;
    font-size: 75%;
    background: beige;
    padding: 2px;
    margin: 2px;
    }

    </style>
    <script type="text/javascript">

    function popit(n)
    {
    var w, wname = 'pop' + n;
    var l = 100 * n + 100;
    var t = 100 * n + 100;
    w = window.open('javascript:"<h4>'+wname+'</h4>"',
    wname,
    'width=200,height=200,left='+l+',top='+t+',status= 0');
    addName(wname);
    return false;
    }

    function addName(wname)
    {
    self.name += (wname + '@');
    }

    function closeByName(wname)
    {
    window.open('javascript:"<script>window.close()<\/script>"', wname);
    }

    function closeAll()
    {
    var wname,
    wcoll = self.name.split('@');
    self.name = '';
    for (var i = 0, l = wcoll.length; i < l; ++i)
    if (wname = wcoll)
    closeByName(wname);
    return false;
    }

    </script>
    </head>
    <body>
    <form>
    <input id="w1" type="button"
    value="open pop 1"
    onclick="popit(1)" />
    <br />
    <input id="w2" type="button"
    value="open pop 2"
    onclick="popit(2)" />
    <br />
    <input id="w3" type="button"
    value="open pop 3"
    onclick="popit(3)" />
    <br /><br />
    <input id="ca" type="button"
    value="close all"
    onclick="closeAll()" />
    </form>
    </body>
    </html>
    sateeshranga, Aug 7, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zEE
    Replies:
    1
    Views:
    6,120
    Islamegy®
    Apr 25, 2006
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,083
    David Schwartz
    Dec 9, 2003
  3. Replies:
    1
    Views:
    239
  4. Replies:
    3
    Views:
    390
    Chung Leong
    Jan 16, 2005
  5. Jaggu
    Replies:
    7
    Views:
    217
    Thomas 'PointedEars' Lahn
    May 22, 2006
Loading...

Share This Page