JS,如何检测打印窗口的打印请求? [英] JS, How to detect the print requests of the print window?

查看:98
本文介绍了JS,如何检测打印窗口的打印请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 打印并提交

的表单和按钮.

单击该按钮将调用Ajax请求,该请求正在创建PDF,并使用 PrintJS 插件在打印窗口"中打开它(

我找到了此解决方案 https://www.tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/,但在我的情况下不起作用.只有在使用 CTRL + P 组合

时,它才有效

解决方案

这是一个棘手的问题.我检查了您共享的链接,是的,它仅适用于ctrl + p,并且也适用于一次(以我为例)我建议尝试添加确认框并接受用户的输入.您可以添加确认框印后方式并检查用户输入.根据用户输入,您可以调用Submit()方法.但这仍然是一个棘手的问题.

I have a form and button in it called Print and Submit

The click on that button calls Ajax request which is creating PDF and open it in Print Window using PrintJS plugin ( http://printjs.crabbly.com/ )

I want to call $('#form').submit() after print requests ( Print or Cancel )

I've found this solution https://www.tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/ but it doesn't work in my case. It works only when I'm using CTRL + P combination

解决方案

This is a tricky problem. I checked the link you shared and yes it works with ctrl+p only and that too once (in my case) I would suggest to try and add confirm box and take input from user. You can add confirm box afterprint method and check on the input from user. Based on user input you can call the submit() method. But still it is tricky one.

这篇关于JS,如何检测打印窗口的打印请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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