I can download the PDF using AngularJS in Chrome, but it doesn't seem to work in the latest FireFox, Internet Explorer 11 or Edge (assuming it doesn't work for IE10), and I know a padding is needed for IE9 . I don’t know if this is the best gasket for this if someone has an opinion, but at the moment it does not work. I tried it with the type of answer bloband arraybufferjust in case that made a difference, and it is not.
All of this means that caniuse points to the use of Blob URLs. Does anyone have work in IE9 and above, as well as in recent versions of FF, and can indicate what I am doing wrong?
$http({
url: '/api/v1/download',
method: 'GET',
responseType: 'blob'
}).then(function (response) {
var url = URL.createObjectURL(response.data);
anchor.href = downloadUrl;
anchor.download = filename;
anchor.target = '_blank';
anchor.click();
URL.revokeObjectURL(downloadUrl);
anchor = null;
}).catch(function (reason) {
console.log('FAIL', reason);
});
UPDATE
() IE10, 11, Edge, FF Chrome. IE9 , - polyfill/shim/other/etc, Safari , SPA, , TODO.
, , , , IE9 Safari, :
function performDownload(blob, filename) {
if(isIE() == 9) {
}
else if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(blob, filename);
}
else {
var URL = window.URL;
var downloadUrl = URL.createObjectURL(blob);
var anchor = document.createElement('a');
if(angular.isDefined(anchor.download)) {
anchor.href = downloadUrl;
anchor.download = filename;
anchor.target = '_blank';
document.body.appendChild(anchor);
anchor.click();
$timeout(function () {
URL.revokeObjectURL(downloadUrl);
document.body.removeChild(anchor);
anchor = null;
}, 100);
}
else {
}
}
}