Reputation: 145
In my chrome browser version 17.0.942.0 winvista the printdlg is not the usual modal system-printdlg but renderered within the website itself. So I want to print canvas content as described here. But the code
window.print();
window.close();
wont work, because window.close
also closes the printdlg. So in chrome window.close
must be initiated by the user or delayed somehow. Is there a way to know if window.print
was finished, so that the window can be closed automatically?
Upvotes: 4
Views: 12063
Reputation: 1
You could try to use window.onafterprint. For example:
window.onafterprint = function(){console.log('Print finished...')}
Then you could find more details in this post: http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
Upvotes: 0
Reputation: 383
add this script to your popup print window
<script src="/assets/print_window_close.js" type="text/javascript"></script>
contents of print_window_close.js is
jQuery(document).ready(function() {
setTimeout(function() {
window.close();
}, 1);
});
basically seTimeout is called only when the document is focused which happens only when the overlay print dialog is closed. hence this works exactly the same way you wanted.
Upvotes: 4
Reputation: 927
Check this comment on a bug report similar to what you are experiencing: http://code.google.com/p/chromium/issues/detail?id=92107#c31
It seems like window.print
is async, the workaround is to check for a mouse movement event after the print, which would occur when the print dialog is closed, then you can perform the rest of your actions.
Also see: Chrome window.print() window.close() results in 'print preview failed'. Solution?
Upvotes: 4