admin管理员组

文章数量:1401664

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');
           //   }

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');
           //   }
Share Improve this question asked Sep 21, 2015 at 1:07 jearcajearca 2351 gold badge4 silver badges13 bronze badges 2
  • This might help you. – J Santosh Commented Sep 21, 2015 at 2:16
  • 2 it's almost 2021 and I still can't know if my user is clicking a button !? – user12163165 Commented Aug 31, 2020 at 22:27
Add a ment  | 

1 Answer 1

Reset to default 3

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.

本文标签: javascriptDetect if windowprint is confirm or cancelStack Overflow