JS Base64字符串可下载pdf - Edge [英] JS Base64 string to downloadable pdf - Edge

查看:891
本文介绍了JS Base64字符串可下载pdf - Edge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在所有浏览器和平台上,我可以使用以下命令将bse64字符串转换为PDF文件:

I have an issue at them moment, where in all browsers and platforms, I can convert a bse64 string to a PDF file using:

function runReport_onComplete(response)
{
    var element = document.createElement('a');
    element.setAttribute('href', encodeURI("data:application/pdf;base64," + response.Report));
    element.setAttribute('download', "LoginInquiry.pdf");
    element.style.display = 'none';
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);
}

我做了一些研究,但我找不到解决办法我可以在其中指定文件名,并在Edge中自动下载文件。

I have done some research, but I have not been able to find a solution where I can specify the file name, and have the file download automatically in Edge.

提前感谢您的帮助。

推荐答案

如果我没记错,这是IE中的一般问题,而不仅仅是Edge。可以使用msSaveOrOpenBlob()在IE中保存命名blob:

If I recall correctly, that is a general problem in IE and not just Edge. One can save named blobs in IE by using msSaveOrOpenBlob():

var tF = 'Whatever.pdf';
var tB = new Blob(..);

if(window.top.navigator.msSaveOrOpenBlob){
    //Store Blob in IE
    window.top.navigator.msSaveOrOpenBlob(tB, tF)
}
else{
    //Store Blob in others
    var tA = document.body.appendChild(document.createElement('a'));
    tA.href = URL.createObjectURL(tB);
    tA.download = tF;
    tA.style.display = 'none';
    tA.click();
    tA.parentNode.removeChild(tA)
}

这篇关于JS Base64字符串可下载pdf - Edge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆