问题
I use angular 1.5 to get a PDF file from an API.
Here is my code :
$http.get('http://www.example.com/pdf.php')
.then(function(response) {
if (response) {
// get pdf
try {
var isFileSaverSupported = !!new Blob;
var blob = new Blob([response.data], {type: "application/pdf;charset=utf-8"});
FileSaver.saveAs(blob, "Test file.pdf");
} catch (e) {
var w = window.open();
var doc = w.document;
doc.open( 'application/pdf','replace');
doc.charset = "utf-8";
doc.write(response.data);
doc.close();
doc.execCommand("SaveAs", null, "Test file IE.pdf");
}
}
});
It works on Chome / FF / IE10+, but of course, IE9 is not. I have a new page opened in IE9 but it contains like :
%PDF-1.5 %��3 0 obj <>stream x���O��}�g��SvYeMe �4��(ID!k�����I e ��AȖd˘}�~�{�}��|���9ϻ��:L��� �E�YD}���݅����.U����X�
Did I miss something ? or is it really impossible to download a file using IE9 ?
来源:https://stackoverflow.com/questions/42901765/download-pdf-file-from-api-using-javascript-ie9