title: JavaScript window.open() doesn't load window immediately
body: <p>I have below code. It tries to open a window on line 6. But it keeps loading (shows processing in title bar with blank content in the window). When I step through the code in the debugger and move on line 10 completing execution of line 9, the window finally loads, giving me error</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property '0' of null on line 9.</p>
  </blockquote>
  
  <p>I don't get why <code>window.open()</code> does not complete loading web page immediately on <code>window.open()</code> and why it always complete loading when I pass through line 9.</p>
  
  <pre><code>var pageURL='url';
  var w=500;
  var h=500;
  var left = (screen.width/2)-(w/2);
  var top = (screen.height/2)-(h/2);
  var targetWin = window.open (pageURL, "_blank",'toolbar=no, location=no,directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
  var windowStr = targetWin.document.documentElement.innerHTML;
  var divMatch = windowStr.match(/someregex/);
  console.log(divMatch[0]);
  </code></pre>
  
  <p>After reading suggestions online I put following after line 6, but same behavior!!!</p>
  
  <pre><code>targetWin.document.close();
  </code></pre>
  
  <p>What's going on here? I am debugging in Chrome.</p>