捕获(不同)打印/取消打印按钮事件(单击)

编程入门 行业动态 更新时间:2024-10-12 16:23:47
本文介绍了捕获(不同)打印/取消打印按钮事件(单击)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

我测试的代码包含在这里:

(function() { var beforePrint = function() { console.log('Functionality to run before printing.'); }; var afterPrint = function() { console.log('Functionality to run after printing'); }; if (window.matchMedia) { var mediaQueryList = window.matchMedia('print'); mediaQueryList.addListener(function(mql) { if (mql.matches) { beforePrint(); } else { afterPrint(); } }); } window.onbeforeprint = beforePrint; window.onafterprint = afterPrint; }());

推荐答案

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

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.

更多推荐

捕获(不同)打印/取消打印按钮事件(单击)

本文发布于:2023-11-11 05:30:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!