In my application, I tried to print out a voucher page for user, I used:
var htm ="<div>Voucher Details</div>";
$('#divprint').html(htm);
window.setTimeout('window.print()',2000);
'divprint
' is a div
in my page which store information about the voucher.
It works, and the print page pops up. But I want to further proceed the application once user
click 'print
' or 'close
' the pop up window.
for example, I'd like to redirect user to another page after pop up window is closed:
window.application.directtoantherpage();//a function which direct user to other page
How to determine the pop up print window is closed or print is finished?
compatible with chrome, firefox, opera, Internet Explorer
Note: jQuery required.
Given that you wish to wait for the print dialog to go away I would use focus binding on the window.
By putting in the unbind in the handler function we prevent the focus event staying bond to the window.
This Actually worked for me in chrome. I was pretty suprised.
Where Print is a function I wrote that calls window.print(); It also works as a pure blocker if you disable Print();
As noted here by user3017502
window.print() will pause so you can add an onPrintFinish or onPrintBegin like this
You can detect when window.print() is finished simply by putting it in another function
tested in Firefox,Google chrome,IE
I think the window focus approach is the correct one. Here is an example in which I wanted to open a PDF url blob in a hidden iframe and print it. After printed or canceled, I wanted to remove the iframe.
Print in new window with w = window.open(url, '_blank') and try w.focus();w.close(); and detect when page is closed. Works in all browsers.
Window close after finish print.