jquery 在print.js中是否需要等待打印窗口关闭

n3h0vuf2  于 2023-08-04  发布在  jQuery
关注(0)|答案(2)|浏览(236)

我有一些使用print.js打印元素的jquery代码,它工作正常,但我需要知道我是否可以检查打印窗口是否关闭并重新加载页面

printJS('print_paper', 'html');
//do stuff after close print window

字符串

pkbketx9

pkbketx91#

有一个名为onPrintDialogClose的选项,它在“打印”对话框关闭后触发。

printJS({
    type: "html",  // Include other option if needed like style , css .....
    onPrintDialogClose: closedWindow 
  });
}

function closedWindow() {
  alert("Window is closed "); // What ever you want to do after window is closed .
}

字符串

nnsrf1az

nnsrf1az2#

我在下面的链接https://github.com/crabbly/Print.js/issues/348中尝试了slebetman的解决方案,它对我很好

let focuser = setInterval(() => window.dispatchEvent(new Event('focus')), 500);

printJs({

    printable: url,

   onPrintDialogClose: () => {

   clearInterval(focuser);

   // do your thing..

},

onError: () => {

   clearInterval(focuser);

    // do your thing..

  }

});

字符串

相关问题