javascript - how to detect window.print() finish -
in application, tried print out voucher page user, used:
var htm ="<div>voucher details</div>"; $('#divprint').html(htm); window.settimeout('window.print()',2000);
'divprint
' div
in page store information voucher.
it works, , print page pops up. want further proceed application once user click 'print
' or 'close
' pop window.
for example, i'd redirect user page after pop window closed:
window.application.directtoantherpage();//a function direct user other page
how determine pop print window closed or print finished?
in firefox , internet explorer can listen after print event.
https://developer.mozilla.org/en-us/docs/web/api/window.onafterprint
window.onafterprint = function(){ console.log("printing completed..."); }
it may possible use window.matchmedia functiionality in other browsers.
(function() { var beforeprint = function() { console.log('functionality run before printing.'); }; var afterprint = function() { console.log('functionality run after printing'); }; if (window.matchmedia) { var mediaquerylist = window.matchmedia('print'); mediaquerylist.addlistener(function(mql) { if (mql.matches) { beforeprint(); } else { afterprint(); } }); } window.onbeforeprint = beforeprint; window.onafterprint = afterprint; }());
source: http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
Comments
Post a Comment