【问题标题】:Handle 'Close' event of Print dialog box处理打印对话框的“关闭”事件
【发布时间】:2016-06-27 06:42:35
【问题描述】:

我正在使用PrintArea,我想处理打印对话框(Chrome、Firefox、...)的“关闭”事件。我试过了

window.onclose = function(){
   // do something
}

但它不起作用。

有什么办法吗?

感谢任何解决方案。

【问题讨论】:

标签: javascript jquery


【解决方案1】:
window.print() //or whatever you want to do
window.onfocus=function(){
//user is back
}

【讨论】:

  • 我在 Linux 上使用 Chrome 51
  • 只有在切换浏览器标签时才会触发。 Windows 上的 Chrome。
【解决方案2】:

这样做

window.print() //open the print dialog box
window.onafterprint=function(){
    //do whatever it is you wish to do
}

注意

这仅适用于 Firefox (>6.0) 和 Internet Explorer。

对于包括 Chrome 在内的其他浏览器,请尝试window.matchMedia()

window.print() //open the print dialog box
var printEvent = window.matchMedia('print');
printEvent.addListener(function(printEnd) {
    if (!printEnd.matches) {
        // do whatever you wish to do
    };
});

【讨论】:

  • 谢谢,但它不起作用,我在 Linux 上使用 Chrome 51
  • 不走运。我用的是Printarea插件,嗯嗯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多