0

Safari version < 9.X didn't support download the file. Code to download the file

 function downloadCSV(csv, filename) {
          var downloadContainer = angular.element('<div data-tap-disabled="true"><a></a></div>');

          // var downloadLink = angular.element('<a></a>'),
          var downloadLink = angular.element(downloadContainer.children()[0]),
              blob = new Blob([csv], {
                type: 'text/csv;charset=utf-8;'
              });

          if (window.navigator.msSaveOrOpenBlob) {
            // download file for IE
            navigator.msSaveBlob(blob, filename);
          }
          else {
            downloadLink.attr('href',  window.URL.createObjectURL(blob));
            downloadLink.attr('download', filename);
            downloadLink.attr('style', 'display: none');

            angular.element(document).find('body').append(downloadContainer);

            // need timeout here since appending DOM takes some time
            $timeout(function() {
              downloadLink[0].click();
              downloadLink.remove();
            }, 10);
          }
        }

Our application to allow the admin to download the file and it works for all browser but not Safari 9.1.2(11601.7.7).Is there any workaround to make in download attribute to make download feature works for Safari? Thanks Kim

Kim
  • 315
  • 4
  • 7
  • 13
  • see http://stackoverflow.com/questions/38711803/how-to-download-a-file-without-using-a-element-with-download-attribute-or-a-se also [https://stackoverflow.com/questions/20300547/download-csv-file-from-web-api-in-angular-js] There is a fiddle for the second one here http://jsfiddle.net/RachGal/namkbu60/ – Rachel Gallen May 02 '17 at 19:45
  • Have tried this fiddle on Safari version 9.x and it didn't work – Kim May 02 '17 at 20:48

0 Answers0