单击"Chrome打印"对话框时关闭窗口 [英] Close the window when Chrome print dialog is clicked

查看:58
本文介绍了单击"Chrome打印"对话框时关闭窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击打印对话框"中的"<打印> "按钮时,我想关闭Chrome中的当前选项卡.我尝试使用 window.print() setTimeout(),但这将关闭对话框,即使通过 CANCEL 按钮取消了打印.有什么解决办法吗?

I want to close the current tab in Chrome when the print button in Print Dialog is clicked by the user. I tried with window.print() and setTimeout(), but this will close the dialog even if the print is canceled by the CANCEL button. Is there is any solution for this?

这是我到目前为止所做的:

This is what I have done so far:

function printThis(){
    window.print();
    setTimeout(function(){
        window.close();
    },5000);
}

推荐答案

您可以使用 onafterprint 事件:

window.onafterprint = function(){ window.close() }

这篇关于单击"Chrome打印"对话框时关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆