1

In my application I am receiving a large file from sever (in post response) and I want to download it at client side using javascript. I fount out there is a download attribute that works with chrome and there is a msSaveBlob function that works with IE. But none of them works with Safari. how can I fix the safari? below is my code:

$scope.saveAs = function (data, filename, type) {    
    if (angular.isUndefined(type)) {
    type = 'application/vnd.ms-excel';
}
var blob = new Blob([data], {'type': type});
if (angular.isDefined(window.navigator.msSaveBlob)) {
    // IE workaround for HTML7007
    window.navigator.msSaveBlob(blob, filename);
} else {
    var URL = window.URL || window.webkitURL;
    var downloadUrl = URL.createObjectURL(blob);

    if (filename) {
        // use HTML5 a[download] attribute to specify filename
        var a = document.createElement('a');
        // safari doesn't support this yet
        if (angular.isUndefined(a.download)) {
            window.location = downloadUrl;
        } else {
            a.href = downloadUrl;
            a.download = filename;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
        }
    } else {
        window.location = downloadUrl;
    }

    setTimeout(function () {
        URL.revokeObjectURL(downloadUrl);
    }, 100); // cleanup
}

};

Am1rr3zA
  • 7,115
  • 18
  • 83
  • 125
  • Take a look at this: http://stackoverflow.com/questions/11336663/how-to-make-a-browser-display-a-save-as-dialog-so-the-user-can-save-the-conten – Hari Lubovac Mar 18 '16 at 18:50

0 Answers0