【问题标题】:Bloburl is not working in IE but working fine in chomeBlob Url 不能在 IE 中工作,但在 chrome 中工作正常
【发布时间】:2019-10-09 11:58:28
【问题描述】:
var newPDF = window.open(this.generatedPDF.output('bloburl'), '_blank');
newPDF.print();

此代码在 Chrome 中运行完美,但在 IE 中使用此代码时我收到警告

您要允许此网站在您的计算机上打开应用程序吗?

点击是,我得到了这个

你需要一个新的应用程序来打开 BLOB

IE 的可能解决方案是什么?

【问题讨论】:

标签: javascript internet-explorer blob bloburls


【解决方案1】:

根据您的描述,我想您想在浏览器中显示 PDF 文件,然后打印。

据我所知,IE 11会阻止blob的显示,如果要显示,首先需要下载,然后在本地查看。

所以,我建议你可以参考下面的代码,使用IE浏览器时先下载文件,然后打印,使用其他浏览器时可以使用你的代码打印:

            // if Internet Explorer or Edge is used, download it.
            if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                var byteCharacters = atob(result.document);
                var byteNumbers = new Array(byteCharacters.length);
                for (var i = 0; i < byteCharacters.length; i++) {
                    byteNumbers[i] = byteCharacters.charCodeAt(i);
                }
                var byteArray = new Uint8Array(byteNumbers);
                var blob = new Blob([byteArray], {
                    type: 'application/pdf'
                });
                window.navigator.msSaveOrOpenBlob(blob, "output.pdf");
            // for all other web browsers
            } else { 
                //your code to print them
            }    

参考:

Displaying binary file (pdf) in IE 11

How to print Pdf file through window.Print() ?

How to open a pdf downloaded from an API with JavaScript

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 2020-01-23
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多