在Chrome中发现浏览器打印事件有两种不同的方式 [英] Detecting browser print event happens two different ways in Chrome
问题描述
我目前使用最新版本的Chrome(43.0.2357.130),并且在从 使用 然而,当使用Chrome菜单或⌘P打印时,它会记录 这是我使用的代码,在其他浏览器中运行良好。 / p> 再一次清晰起来,好像这是控制台: 这是我期望的输出: 这是我使用⌘P或菜单开始打印时获得的输出: 这是Chrome中的一个错误,还是有另一种方法可以正确捕获事件? 仅供参考,这里是我可以使用支持表来进行 看起来这可能只是Chrome的一个漏洞。 https://bugs.chromium.org/p/chromium/issues/detail ?id = 422883 I am currently using the most up-to-date version of Chrome (43.0.2357.130), and am experiencing a difference in printing functionality when calling print from When printing using However, when using the Chrome menu, or ⌘P to print, it logs both Here is the code I am using, which works well in other browsers. Once again for clarity as if this was the console: This is the output I expect: This is the output I get when I use ⌘P or the menu to start print: Is this a bug in Chrome, or is there another way to capture the event correctly? Just for reference, here is the Can I Use support table for It looks like it is probably just a bug with Chrome. https://bugs.chromium.org/p/chromium/issues/detail?id=422883 这篇关于在Chrome中发现浏览器打印事件有两种不同的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! window.print()$ c>调用打印时遇到打印功能上的差异
window.print()
打印时,它会正确输出到控制台。它在打印对话框打开时输出打印前
,当对话框关闭时输出打印后
。
打印之前
和在打印对话框打开后打印
到控制台。
函数beforePrint(){
console.log('Before Print');
}
函数afterPrint(){
console.log('After Print');
}
if(window.matchMedia){
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql){
(mql.matches)?beforePrint():afterPrint();
});
}
else {
//基本上是< IE11
window.addEventListener('beforeprint',beforePrint,false);
window.addEventListener('afterprint',afterPrint,false);
}
> window.print()
之前打印
//打印对话框现在打开,我按取消关闭对话框
打印
后
之前打印
打印
之后//打印对话框现在打开,但发生在错误的地方
matchMedia
window.print()
vs using ⌘P.window.print()
it outputs to the console correctly. It outputs Before Print
when the print dialog is opened, and After Print
when the dialog is closed.Before Print
, and After Print
to the console when the print dialog opens.function beforePrint() {
console.log('Before Print');
}
function afterPrint() {
console.log('After Print');
}
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function (mql) {
(mql.matches) ? beforePrint() : afterPrint();
});
}
else {
// basically a fallback for < IE11
window.addEventListener('beforeprint', beforePrint, false);
window.addEventListener('afterprint', afterPrint, false);
}
> window.print()
Before Print
// Print Dialog is now open, I press cancel to close dialog
After Print
Before Print
After Print
// Print Dialog is now open, but it is occurring in the wrong place
matchMedia