Results 1 to 2 of 2

Thread: Child windows not closing after refreshing parent page

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Child windows not closing after refreshing parent page

    I have written this code for close all child window with parent window but after refreshing the parent window child window are not closing. Code bellow.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title>window manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <script type="text/javascript">
    var windows = [];
    function conf() {
    var rand_no_c = Math.random();
    var con = rand_no_c.toString();
    var_win = 'child'+con.substring(2);
    windows[var_win] = window.open('test2.html',var_win,'width=400,height=200,left=50,top=20,status=0');
    }
    
    function closewindow() {
    for(w in windows) {
        if(!windows[w].closed) {
            windows[w].close();
            }
        }
    }
    </script>
    
    <style type="text/css">
    * {margin:0;padding:0;}
    </style>
    
    </head>
    <body>
    <div>
        <a href="javascript:"  onclick="conf();">open child window</a>||
        <a href="javascript:"  onclick="conf();">open child window</a>||
        <a href="javascript:"  onclick="conf();">open child window</a>||
        <a href="javascript:"  onclick="conf();">open child window</a>||
        <a href="test2.html">Click</a>
        <button type="button" onclick="closewindow();">close all windows</button>
    </div>
    </body>
    </html>
    Last edited by jscheuer1; 11-30-2010 at 04:07 AM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    With windows there are no parents and children. Those terms are for elements on a single page.

    For distinct windows you have opener (somewhat like parent), and the variable name (if any) you assigned to the opened window when you opened it.

    In any case, once you do a refresh of the opener you lose all reference from it to any page that it had opened, period.

    In most browsers though - you can close the opened window when the opener is refreshed. That might not be an attractive option, but it's really about all you have, so you might be able to get it to work for you.

    If none of this seems adequate, something server side might be better. I'd also ask myself if a new window was even necessary. They can often be blocked by the browser, so should never be used for mission critical data. Most new windows used -say for e-commerce, have their own close button on them and are only used for things like detailed images of the product.
    Last edited by jscheuer1; 11-30-2010 at 04:58 AM. Reason: add detail
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •