【问题标题】:print not workig on IE11打印在 IE11 上不起作用
【发布时间】:2019-09-08 19:45:40
【问题描述】:

我正在使用 blob url 和 iFrame 来打印文档。它在 Chrome 中运行良好,但在 IE 中无法运行。

谁能告诉我如何打印在 iframe src 中设置的 blob url?

let file = new Blob([res.blob()], { type: 'application/pdf' });

let blobURL = URL.createObjectURL(file);// here file is blob object
let iframe = document.createElement('iframe');                        

document.getElementById('viewerContainer').appendChild(iframe);

iframe.onload = function () {
    iframe.contentWindow.print();
};

iframe.src = blobURL;

【问题讨论】:

  • 请比“但不工作”更精确。任何错误(在控制台中)?
  • 有什么错误吗?你检查过网络开发工具(F12)吗?
  • 我正在使用 12 页的文档。当我尝试打印所有页面时,此代码仅适用于第一页。
  • 控制台未发现错误

标签: javascript angular file blob


【解决方案1】:

我不知道 IE7 的具体情况,但我在 Firefox 中遇到了类似的错误。这会在内容完全加载之前触发 onload 事件。不幸的是,我找不到解决方案。所以我巧妙地使用了 setTimeout()。
此解决方案很弱,但您可以使用 setTimeout(time) 和一个允许您加载文档全部内容的时间。 警告这次取决于网络连接

【讨论】:

  • 你需要修改你的答案。不要将重要信息放在评论中。
  • 这对我不起作用。当我为 IE11 使用 iframe.contentWindow.print() 时,它只打印包含所有可见网站内容的文档的第一页
  • setTimeout(iframe.contentWindow.print(), 5000)也是一样的?
  • 让 iframe = document.createElement('iframe'); document.body.appendChild(iframe); iframe.onload = function () { setTimeout(iframe.contentWindow.print(), 5000) }; iframe.src = blobURL;
猜你喜欢
  • 2015-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-16
  • 1970-01-01
  • 2013-08-06
  • 2021-06-03
  • 2023-03-31
  • 2015-08-13
相关资源
最近更新 更多