Is there a way to close the active tab in the browser after I sent the data to the reprint?

<script> window.print(); </script> 

It means, how to make so that after clicking the "Print" button, the tab is automatically closed? example

  • Tabs or pop-ups? - Dmitriy Gvozd
  • Exclusively tabs - Roma Tulaydan
  • You can close the tab by controlling the browser from the outside, for example, selenium webdriver, JS does not help here, as far as I know. - Dmitry Nail
  • I want to understand how you can immediately close the printout window by clicking the Print button. This is possible on many sites running. But I don’t know how to do it - Roma Tulaydan

1 answer 1

In order for you to close a tab using JavaScript, you need to open it using JavaScript.

For example:

On the page with the submit button

 <input value="Печатать" onclick="window.open('http://mysite.ru/print-page')" type="button"> 

On the page mysite.ru/print-page

 <script> setTimeout(function(){window.print();}, 500); window.onfocus = function(){setTimeout(function(){window.close();}, 500);}; <script> 

The delay in this case is necessary so that in such browsers as Chrome the print window does not close before calling the print method.