Printing with javascript in chrome: how do I know if printing is complete?

In my Chrome browser version 17.0.942.0, winvista printdlg is not a regular modal system-printdlg, but is rendered inside the website itself . Therefore, I want to print the contents of the canvas as described here . But the code

window.print(); window.close();

does not work because window.close also closes printdlg. So in chrome window.close should be user initiated or somehow delayed. Is there a way to find out if window.print completed so that the window window.print automatically?

+4
source share
4 answers

Mark this comment in a bug report similar to what you are experiencing: http://code.google.com/p/chromium/issues/detail?id=92107#c31

window.print be asynchronous, the workaround is to check the mouse move event after printing, which happens when the print dialog is closed, and then you can do the rest.

See also: Chrome window.print () window.close () generates a Print Preview error. Decision?

+4
source

add this script to the popup window

 <script src="/assets/print_window_close.js" type="text/javascript"></script> 

contents of print_window_close.js

 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 dialog is closed. therefore, it works exactly the way you wanted.

+4
source

You can try using window.onafterprint. For instance:

 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/

0
source

This works for me, you have to get listeners to print the event: https://gist.github.com/vluzrmos/085975de3e1840936604

-1
source

Source: https://habr.com/ru/post/1382495/


All Articles