嗨,我正在使用 PrintJs javascript 库。我在 OnPrintDialogClose 选项中分配了一个回调函数。它不会在打印预览窗口关闭后立即触发,而是仅在我切换到新的浏览器选项卡或在 Windows 操作系统上按 Alt+Tab 后触发。有谁知道为什么打印预览窗口关闭后没有触发。
这是我的Codepen sample
这是我的 JavaScript 代码片段。
<script>
var afterPreviewClose = function(){
window.location = "index.html";
};
$("#btnPrint").on("click",function(){
printJS({
printable: 'print-area',
type: 'html',
onPrintDialogClose: afterPreviewClose,
css: 'styles/styles.css' });
});
</script>
最佳答案
我在以下链接中尝试了 slebetman 的解决方案 https://github.com/crabbly/Print.js/issues/348
let focuser = setInterval(() => window.dispatchEvent(new Event('focus')), 500);
printJs({
printable: url,
onPrintDialogClose: () => {
clearInterval(focuser);
// do your thing..
},
onError: () => {
clearInterval(focuser);
// do your thing..
}
});
关于javascript - 打印预览关闭后未触发 OnPrintDialogClose 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63446345/