我有一些使用 print.js 打印元素的 jquery 代码,它工作正常,但我需要知道是否可以检查打印窗口是否关闭并重新加载页面
printJS('print_paper', 'html');
//do stuff after close print window
我有一些使用 print.js 打印元素的 jquery 代码,它工作正常,但我需要知道是否可以检查打印窗口是否关闭并重新加载页面
printJS('print_paper', 'html');
//do stuff after close print window
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 .
}
我在以下链接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..
}
});