1

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

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

2 回答 2

2

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 .
}
于 2019-09-30T06:46:24.547 回答
2

我在以下链接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..

  }

});
于 2020-10-19T12:05:42.827 回答