שלום!יש לי String המכיל XmlDocument ואני צריכה לייצר ממנו קובץCsv ולהוריד למחשב. דוקא בקליינט ולא בסרבר.איך עושים זאת?
מצאתי בעצמי תשובה:
function downloadCsv(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';
if (navigator.msSaveBlob) { // IE10
navigator.msSaveBlob(new Blob([content], { type: mimeType }), fileName);
} else if (URL && 'download' in a) { //html5 A[download]
a.href = URL.createObjectURL(new Blob([content], { type: mimeType }));
a.setAttribute('download', fileName);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
location.href = 'data:application/octet-stream,' + encodeURIComponent(content); // only this mime type is supported
}
}
הקריאה לפונקציה היא:
downloadCsv(csvContent, 'download.csv', 'text/csv;encoding:utf-8');