title: Open new tab/window and close old one
body: <p>Here is my current code, but the <code>closeWindow</code> function is executed before the new tab opens.</p>
  
  <pre><code>    $(document.body).append('&lt;iframe width="500px" height="500px" id="pcl_frame" style="display:none;"&gt;&lt;/iframe&gt;');
      $('#pcl_frame').attr('src', data['url']);
      $('#pcl_frame').load(function() {
          // Load page
          document.getElementById('pcl_frame').contentWindow.CreateCBTPlayer(data['code'],"new");
  
          // Close current windows after the above tab/window opens
          closeWindow(); // has a 2 second delay
  }); 
  </code></pre>
  
  <p>Is there a way to wait for the command above to open the new tab/window first, then close the current tab that was used to open the new window.</p>
  
  <p>Also I can't change the <code>CreateCBTPlayer</code> function.</p>
  
  <h3>Disclaimer</h3>
  
  <p>I know what I'm doing isn't very logical, but it has to be done to get around an old system I have to work with. </p>