捕获(不同)打印/取消打印按钮事件(单击) [英] Capture (distinct) Print / Cancel Print Button Event (click)

查看:762
本文介绍了捕获(不同)打印/取消打印按钮事件(单击)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何才能仅捕获打印页面中的取消事件?

How can I capture only the cancel event from the print page?

我有一个页面,单击按钮后,您会打开一个新选项卡,其中加载了打印内容,如果您单击取消"(不是打印),则必须调用一个方法.打印相同.

I have a page that on a button click you have a new tab opened with print loaded, there if you click cancel (not print) I have to call a method. Same for print.

如果要打印,则要执行PrintSuccesfully(),如果要取消打印,我要执行PrintCancelled().

In case of print a want to execute PrintSuccesfully(), if Cancel print I want to execute PrintCancelled().

打开新标签的代码:

var windowObject = window.open('', '_blank');
windowObject.document.write(generatePrintHTMLBody(scope));
windowObject.document.close();
windowObject.focus();
windowObject.print();
windowObject.close();

我在beforeprint和onafterprint上进行了查找,但是都使用matchMedia,在CTRL + P事件上或在单击打印/取消"按钮时在我的代码上执行.

I looked up onbeforeprint and onafterprint, but both are executed with matchMedia, on CTRL+P event or on my code at Print / Cancel button click.

我测试的代码包含在

推荐答案

经过大量研究,您似乎无法执行此操作……每个浏览器上按钮的行为不同,或者具有相同的签名,因此没有解决方案存在.

After a lot of research it seems you cannot do this... The behaviour si diferent for the buttons on each browser or it has the same signature, so no resolution exists.

这篇关于捕获(不同)打印/取消打印按钮事件(单击)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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