title: iPad Safari IOS 5 window.close() closing wrong window
body: <p>We have an iPad application that's working on our older iPads.</p>
  
  <p>We open external links using
  var x = window.open(url)</p>
  
  <p>at the end of the day, when the user closes this part of the app, we go through all the windows it opened and do x.close() for each one and everything is okie dokie.</p>
  
  <p>Testing on the new iPad with IOS 5 and the lovely tabs,
  opening the new windows (although now they open as tabs) is fine, but doing x.close() doesn't seem to necessarily close x, it may close window y or z. Doing x.focus() or y.focus() works just fine, the correct tab comes into focus, but close seems to just pick whatever tab it wants.</p>
  
  <p>Is this a bug or am I doing something wrong? Example program:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
      &lt;script&gt;
          //The openWindow array will hold the handles of all open child windows
          var openWindow = new Array();
         var win1;
         var win2;
          //Track open adds the new child window handle to the array.
          function trackOpen(winName) {
              openWindow[openWindow.length]=winName;
          }
  
          //loop over all known child windows and try to close them.  No error is
          //thrown if a child window(s) was already closed.
          function closeWindows() {
              var openCount = openWindow.length;
              for(r=openCount-1;r&gt;=0;r--) {
                  openWindow[r].close();
              }
          }
  
          //Open a new child window and add it to the tracker.
          function open1() {
              win1 = window.open("http://www.yahoo.com");
              trackOpen(win1);
          }
  
          //Open a different child window and add it to the tracker.
          function open2() {
              win2 = window.open("http://www.google.com");
              trackOpen(win2);
  
          }
          //Open whatever the user enters and add it to the tracker
          function open3() {
              var newURL = document.getElementById("url").value;
              var win3= window.open(newURL);
              trackOpen(win3);
          }
  
      &lt;/script&gt;
      &lt;input type="button" value="Open 1" onclick="open1()"&gt;
      &lt;input type="button" value="Open 2" onclick="open2()"&gt;
      &lt;input type="button" value="Focus 1" onclick="win1.focus()"&gt;
      &lt;input type="button" value="Focus 2" onclick="win2.focus()"&gt;
      &lt;input type="button" value="Close 1" onclick="win1.close()"&gt;
      &lt;input type="button" value="Close 2" onclick="win2.close()"&gt;
  
      URL: &lt;input type="text" id="url"&gt; &lt;input type="button" value="Open URL" onclick="open3()"&gt;
      &lt;input type="button" value="Close All" onclick="closeWindows()"&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>