title: Handling of child and grandchild windows in Javascript
body: <p>I have a main window (#1) on my webpage from which I open a new browser window (#2) from which I open a new window (#3).</p>
  
  <p>Now if my user closes window#2 before window#3, I have the problem that window#3 no longer can call function in its window.opener since it has gone away.</p>
  
  <p>What I would like to do is to set window#3.opener to window#1 when window#2 closes.</p>
  
  <p>I've tried to do this i window#2 (by the way I use jquery):</p>
  
  <pre><code>var children = [];
  $(window).unload( function( ) {
      $.each( children, function( p, win ) {
          if ( win ) {
              win.opener = window.opener;
              }
      } );
  } );
  </code></pre>
  
  <p>When window#3 is loaded I add the window to the array children in window#2.</p>
  
  <p>But still when window#2 is closed before window#3, windows#3's window.opener doesn't point to window#1.</p>
  
  <p>How do I make sure that my grand child window (window#3), can still call the main window (window#1) after window#2 is closed?</p>