Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if window.print is confirm or cancel

Tags:

javascript

hello i have a code for print, i do a window open, and this pop-up contain all info for print, and i using the kiosk-printing for automatic printing but that fails sometime, if chrome is open with other instance for example, them i having problems because i need to confirm each print, then i need to know if exist a method for confirm what button press the client in Print Dialog(Print or Cancel).

 var printWindow = window.open(windowUrl, windowName, 'left=500,top=100,width=10,height=10');
             printWindow.document.body.innerHTML = HTL;
             printWindow.document.close();
             printWindow.focus();
             printWindow.print(); // maybe here return if user press print or cancel

           // if(ConfirmPrint=="print"){
            // alert('Print Button');
            //}else{
           //    alert('Cancel Button');
           //   }
like image 763
jearca Avatar asked Oct 30 '22 18:10

jearca


1 Answers

Sadly, window.print() doesn't return any value. So, there's no way to know if the user clicked Save or Cancel. It's more of your operating system's job to watch what's going on in there. There're, however, two event handlers: window.onbeforeprint and window.onafterprint.

The afterprint event is raised after the user prints or aborts a print dialog.

But again, it's a simple event and it's not telling you which option is selected by the user. And also these two events are not well supported.

like image 200
Gökay Gürcan Avatar answered Nov 08 '22 10:11

Gökay Gürcan