title: Open multiple javascript popup boxes with one button click
body: <p>This is a JavaScript question. </p>
  
  <p>I need to create a button which, when clicked once, will open up 5 sub-windows (popup boxes).</p>
  
  <p>One box will be in the top left corner of the screen, one in the top right corner, one in the lower left corner, one in the lower right corner, and one in the center. Each box will have a different URL.</p>
  
  <p>When the main window is closed, all of the sub-windows should also close.</p>
  
  <p>I have only been able to do the code that opens one popup - cannot figure out how to code all 5 to open at once with one button click and then close them all when the parent window closes.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>&lt;SCRIPT language="JavaScript"&gt;
  function myPopup(URL) {
  popupWindow = window.open(URL,'popUpWindow','height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
  }
  &lt;/SCRIPT&gt;
  
  &lt;a href="#" onclick="myPopup(this.href);return false"&gt;Open Pop-Up&lt;/a&gt;
  </code></pre>
  
  <p>Many thanks to anyone who can help me out.</p>
  
  <hr>
  
  <p>Thanks to everyone who is helping me. By utilizing the feedback here, I have worked on this project all day and have come up with some code that works. I was not sure how to assign urls for each popup to the array - but at least they work.</p>
  
  <p>However, I can not get all the popups to close when the parent window closes. Hope you can help. Here is the new code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  /*Use Array - Open 5 new popup windows using onclick*/
  
  function newWindow() {
   var winPop = new Array();
    winPop[winPop.length] = window.open('top_right.html','window1','scrollbars=no,width=235,height=155,left=1000,top=200,screenX=1000,screenY=200');
  window.open('top_left.html','window2','scrollbars=no,width=235,height=155,left=325,top=200,screenX=325,screenY=200');
  window.open('bottom_left.html','window3','scrollbars=no,width=235,height=155,left=325,top=600,screenX=325,screenY=600');
  window.open('bottom_right.html','window4','scrollbars=no,width=235,height=155,left=1000,top=600,screenX=1000,screenY=600');
  window.open('center_page.html','window5','scrollbars=no,width=235,height=155,left=660,top=450,screenX=660,screenY=450');
  }
  
  /*NOT WORKING FOR ME --Close all popups when parent window is closed*/
  
  onbeforeunload = function() {
      for (var index = 0; index &lt; winPop.length; ++index)
          winPop[index].close();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="wrap"&gt; &lt;a href='' onclick='newWindow()'&gt;&lt;img src='images/group_clicker.gif' border='0'&gt;&lt;/a&gt; &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>