QRCode quits when sent to print

0

I'm using a library in PHP that generates the QRCode. The code looks like this:

<?php
    $aux = $caminhoAbsoluto.'/qr_img0.50j/php/qr_img.php?';
    $aux .= 'd=&';
    $aux .= 'e=H&';
    $aux .= 's=10&';
    $aux .= 't=J';
?>
<img id="img" src="<?php echo $aux; ?>" style="width: 180px" />

It generates correctly, the problem is that when I click to print, the QRCode disappears. In some tests that I applied, I noticed that this happens when the window that generates the QRCode for printing is closed, that is, the user clicks on print, the system reads another window where the QRCode is applied and in the end I have this code where the print is opened and the window is closed:

<script>window.print(); setTimeout(window.close(),5000)</script>

When I remove setTimeout(window.close(),5000 the QRCode appears, but when I leave it to close the window, the QRCode does not appear. When I also type the print page directly in the browser, eg www.site.com.br/imprimir.php, it works. How can I resolve this?

    
asked by anonymous 14.12.2018 / 15:28

1 answer

0

Although JavaScript or Jquery is not my strongest, I have managed to solve it this way. Feel free to correct me:

  <script>
  setTimeout(function () {
     window.print(); window.close();
   }, 50); 
  </script>
    
14.12.2018 / 15:48