0

尝试使用 Ctl + P(打印)时,浏览器的 BeforePrint 事件在某些网站上未触发,在 Chromium 浏览器上已检查

  1. Docx、PPTX、XLS、文件保存 box.com 在浏览器中打开(使用 Microsoft 在线打开现有/新文档)
  2. 打印保存在 OneDrive 上的 MS Office 文件(使用 Word 在线打开现有的 MS Office 文档)
  3. 在 Gmail 中打印附件
  4. 在 OWA 中打印附件
  5. 打印演示文稿,保存在 Google Docs 上的电子表格

这是我正在使用的代码,它在其他网页中运行良好。

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 {
    window.addEventListener('beforeprint', beforePrint, false);
    window.addEventListener('afterprint', afterPrint, false);
}
4

0 回答 0