[英]ONAFTERPRINT event fires on the wrong button
I need to know if the user has click the print
or cancel
button but onafterprint
event fires if either was clicked, why ??我需要知道用户是否点击了print
或cancel
按钮,但如果点击了其中之一,则onafterprint
事件会触发,为什么?
window.onafterprint = () => {
// event should fire only if print button is clicked
}
Enter this page and do the Ctrl + p
try to cancel
or print
or save
the document and watch the alert
进入此页面并执行Ctrl + p
尝试cancel
或print
或save
文档并观看alert
can anyone please explain ?谁能解释一下?
The afterprint event is fired after the associated document has started printing or the print preview has been closed. afterprint 事件在相关文档开始打印或打印预览关闭后触发。 MDN MDN
It seems that you can't know through the event.好像不能通过事件知道。 The specification does not tell user agents to distinguish between printing or canceling the print prompt.该规范没有告诉用户代理区分打印或取消打印提示。 Although the spec is quite vague about what to actually do.尽管规范对实际做什么非常模糊。 WHATWG Spec . WHATWG 规范。
The onafterprint event occurs when a page has started printing, or if the print dialogue box has been closed. onafterprint 事件发生在页面开始打印时,或者如果打印对话框已关闭。 That's why the event fires with both buttons.这就是为什么用两个按钮触发事件的原因。
So, there's no way to know if the user clicked Save or Cancel.因此,无法知道用户是单击了保存还是取消。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.