问题
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);
}
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.
Thanks in advance for the help.
回答1:
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)
}
来源:https://stackoverflow.com/questions/40724578/js-base64-string-to-downloadable-pdf-edge