For anyone to stumble upon this reply from Google, let me try to clarify things:
As Ajay pointed out, there are two events that are fired for printing but they are not well supported; as far as I have read, they are only supported on (6+) Internet Explorer and Firefox browsers. These events are window.onbeforeprint and window.onafterprint, which (as you would expect) will be triggered before and after the print job.
However, as pointed out in Joe’s call ( https://stackoverflow.com/a/9920784/578667 ), This is not exactly how it is implemented in all cases. In most cases, both events trigger before the dialog; in others, the script execution may be interrupted during the print dialog, so both events can trigger at the same time (after the dialog has been completed).
For more information (and browser support) for these two events:
https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeprint
https://developer.mozilla.org/en-US/docs/DOM/window.onafterprint
The short answer: if you’re waiting to interfere with the print flow, they don’t. If you are waiting to trigger the code after printing, it will not work as you want; expect poor browser support, and try to degrade normally.
Source : https://stackoverflow.com/questions/11138939/how-to-trigger-javascript-on-print-event
But when you click cancel or close after printing it doesn’t come back? I don’t understand.
– Ivan Ferrer
It opens the print window, when I select the printer and print it closes the window, exactly as I needed.
– Diego