标签:javascript google-chrome printing
我目前正在使用最新版本的Chrome(43.0.2357.130),在使用window.print()和使用⌘P调用print时,我遇到了打印功能的差异.
使用window.print()打印时,它会正确输出到控制台.打开打印对话框时输出Before Print,关闭对话框时输出After Print.
但是,在使用Chrome菜单或⌘P进行打印时,它会在打印对话框打开时将“打印前”和“打印后”记录到控制台.
这是我正在使用的代码,在其他浏览器中运行良好.
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
这是我使用⌘P或菜单开始打印时得到的输出:
Before Print
After Print
// Print Dialog is now open, but it is occurring in the wrong place
这是Chrome中的错误,还是有其他方法正确捕获事件?
仅供参考,这里是matchMedia的Can I Use support table
解决方法:
看起来它可能只是Chrome的一个错误. https://bugs.chromium.org/p/chromium/issues/detail?id=422883
标签:javascript,google-chrome,printing 来源: https://codeday.me/bug/20191007/1869245.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。