Firefox cannot downloand CSV file from json API in AngularJS/JS project -


i working on angularjs/js project, let user download table data json api data csv data. code works fine in chrome, wouldn't work in firefox. title of downloaded csv file contains spaces like: "financial balance report.csv", removed blank space, still wouldn't work. 1 can help? please see code below:

//convert json object csv   $scope.convertarrayofobjectstocsv = function(args) {             var result, ctr, keys, columndelimiter, linedelimiter, data;              data = args.data || null;             if (data == null || !data.length) {                 return null;             }              columndelimiter = args.columndelimiter || ',';             linedelimiter = args.linedelimiter || '\n';              keys = object.keys(data[0]);              result = '';             result += keys.join(columndelimiter);             result += linedelimiter;              data.foreach(function(item) {                 ctr = 0;                 keys.foreach(function(key) {                     if (ctr > 0) result += columndelimiter;                     if(typeof(item[key]) === "string" && item[key].includes(",")){                             item[key] = item[key].replace('\"', """);                     }                     result += '"' + item[key] + '"';                     ctr++;                 });                 result += linedelimiter;             });             return result;         }  // download csv data   $scope.downloadcsv = function (args) {         var data, filename, link;          var stringdata = angular.tojson($scope.data.items);          $scope.newdata = json.parse(stringdata);          var csv = $scope.convertarrayofobjectstocsv({              // convert api json data csv             data: $scope.newdata          });          if (csv == null) return;          // selectedkeys table title, got api         filename =  $scope.selectedkeys[0] + '.csv';          if (!csv.match(/^data:text\/csv/i)) {             csv = 'data:text/csv;charset=utf-8,' + csv;         }         data = encodeuri(csv);          link = document.createelement('a');         link.setattribute('href', data);         link.setattribute('download', filename);         link.click();     } 

html:

  // create button in html enables user download. works fine in chrome, firefox    <button id="downloadbtn" ng-click='downloadcsv({ filename: "your_report.csv" });'>download   </button> 


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -