title: Javascript window.close() in chrome, closes all the tab at once when many tabs at once opened from a link
body: <pre><code>document.addEventListener("DOMContentLoaded", printFunction);
      function printFunction() {
        //setTimeout(function(){
          var file_name = ("{{article['title']}}".replace(/[^0-9a-zA-Z_?: .]/g, ""));
          document.title="Scroll - "+file_name;
          window.print();
          setTimeout(function(){window.close();}, 1);
        //}, 1);
      }
  </code></pre>
  
  <p>Hey I am trying to print a page by opening a new tab for printing, where <code>Print Preview</code> automatically opens and if user prints or cancel the page, it automatically closes. But when I am opening it on two tabs <code>print preview</code> is only getting loaded on one tab and on other tab <code>print preview</code> is not getting loaded. Is there any workaround for this.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I comment out the setTimeout method and now I am able to open print preview on every tab but when I am closing one print preview my all other tab is getting closed</p>
  
  <p>I am opening my Print page by clicking on a link which is like this</p>
  
  <p><code>a(href="/article/print/{{article['id']}}", target="_blank")</code></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Right now I tried is using <code>_new</code> in place of <code>_blank</code> or tab name. But when I am clicking print from 4 different places 4 tab for different article is opening with print preview but canceling the print preview on one the tab is not getting closed till I am canceling the print preview on the first tab which is opened. Ajax call is also getting stopped.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I have a website which is infinite scrollable. Meaning 1st article I am getting through Flask after that I am using Ajax call to get other articles if user scrolls a bit. Now I have print button on every article. When user is clicking on a certain print button and if I have used  <code>target = _blank</code> a new tab will open with print preview on. Now if he will click again on the print button again a new tab will open with the print preview of that article. Now if he cancels or print the page, the tab should automatically close. But its happening only when user has open one tab. If he has open more than one tab by clicking on Print button then all the print preview tab is getting closed when he cancels the first tab that he has opened and if he cancels the second or third tab then no print preview tab is getting closed till he manage to cancel print on first tab.</p>
  
  <p>For eg:</p>
  
  <p><code>infiniteScroll.html</code></p>
  
  <pre><code>&lt;html&gt;
  &lt;ul&gt;
   &lt;li&gt;
    &lt;a href="print.html" target="_blank"&gt;print&lt;/a&gt;
   &lt;/li&gt;
   &lt;li&gt;
    &lt;a href="print.html" target="_blank"&gt;print&lt;/a&gt;
   &lt;/li&gt;
   &lt;li&gt;
    &lt;a href="print.html" target="_blank"&gt;print&lt;/a&gt;
   &lt;/li&gt;&lt;/ul&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><code>print.html</code></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;p&gt;sldfnksdfsdvncsjdnvjkndsc&lt;/p&gt;
  &lt;script type="text/javascript"&gt;
      document.addEventListener("DOMContentLoaded", printFunction);
      function printFunction() {
      //- setTimeout(function(){
        //- LazyX.load();
        var file_name = ("{{article['title']}}".replace(/[^0-9a-zA-Z_?: .]/g, ""));
        document.title="Scroll - "+file_name;
        window.print();
        setTimeout(function(){window.close();}, 1);
      //- }, 1);
    }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And Moreover my AJAX Call on website is not happening if Print preview tab is not closed.</p>
  
  <p>A bit same problem <a href="https://stackoverflow.com/questions/31033279/google-chrome-blocks-ajax-requests-when-print-preview-modal-is-opened-on-child-w">Stack Question</a></p>
  
  <p><strong>UPDATE/PROBLEMS</strong></p>
  
  <ol>
  <li><p>Open multiple tabs of print preview(BY CLICKING ON ALL 3 PRINT), then I am unable to AUTOMATICALY close the tab after printing or cancel the 2nd/3rd or 4th tab. But if I print or cancel the first opened tab from print I am able to close automatically.</p></li>
  <li><p>If I open multiple tabs of print preview, and if I cancel or print 1st tab all tabs are getting closed.</p></li>
  <li><p>If I open print preview before my AJAX call on infinite page. then I need to wait for the finish of printing page or cancel the print preview.link shared above.</p></li>
  </ol>