如何检测window.print()完成
在我的应用程序中,我尝试为用户打印出凭证页面,如下所示:
  var htm ="<div>Voucher Details</div>";  $('#divprint').html(htm);
  window.setTimeout('window.print()',2000);
“ divprint”是div我的页面中的,用于存储有关凭证的信息。
它有效,并且打印页面弹出。但是,我希望用户一旦在浏览器的弹出式打印对话框中单击“ print”或“ close”,便可以升级该应用程序。
例如,我想在弹出窗口关闭后将用户重定向到另一个页面:
window.application.directtoantherpage();//a function which direct user to other page如何确定何时关闭弹出的打印窗口或打印完成?
回答:
在FireFox和Internet Explorer中,您可以侦听打印后事件。
window.onafterprint = function(){   console.log("Printing completed...");
}
可能可以使用window.matchMedia在其他浏览器中获得此功能。
(function() {    var beforePrint = function() {
        console.log('Functionality to run before printing.');
    };
    var afterPrint = function() {
        console.log('Functionality to 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;
}());
以上是 如何检测window.print()完成 的全部内容, 来源链接: utcz.com/qa/434836.html

