Ich habe ein Array, das ein anderes Array enthält. Ich versuche, dieses Array in einer CSV-Datei über dieses Skript zu speichern, und es funktioniert nicht. Es Download nicht meine Datei ...Speichern von Array-Inhalt als CSV-Datei js
var data =(JSON.stringify(allFileGenesDetails1));
var csvContent = '';
data.forEach(function (infoArray, index) {
dataString = infoArray.join(';');
csvContent += index < data.length ? dataString + '\n' : dataString;
});
var download = function(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';
if (navigator.msSaveBlob) { // IE10
return navigator.msSaveBlob(new Blob([content], { type: mimeType }), fileName);
} else if ('download' in a) { //html5 A[download]
a.href = 'data:' + mimeType + ',' + encodeURIComponent(content);
a.setAttribute('download', fileName);
document.body.appendChild(a);
setTimeout(function() {
a.click();
document.body.removeChild(a);
}, 66);
return true;
} else { //do iframe dataURL download (old ch+FF):
var f = document.createElement('iframe');
document.body.appendChild(f);
f.src = 'data:' + mimeType + ',' + encodeURIComponent(content);
setTimeout(function() {
document.body.removeChild(f);
}, 333);
return true;
}
}
download(csvContent, 'csv file.csv', 'text/csv');
Es ist äußerst wichtig zu wissen, welchen Browser Sie verwenden. Safari unterstützt beispielsweise keine JS-erzwungenen Downloads und unterstützt auch nicht das HTML-Attribut "Download". – NoobishPro