Client side csv download using Blob

suggest change
function downloadCsv(csvString) {
  const blob = new Blob([csvString], { type: "text/csv" });
  if (window.navigator.msSaveOrOpenBlob) {
    // Legacy Internet Explorer.
    window.navigator.msSaveBlob(blob, "filename.csv");
    return;
  }

  const a = document.createElement("a");
  a.href = URL.createObjectURL(blob);
  a.download = "filename.csv";
  document.body.appendChild(a);
  a.click();
  a.remove();
  URL.revokeObjectURL(a.href);
}

downloadCsv("a1,a2,a3");

URL.createObjectURL takes only the blob. The MIME type belongs on the Blob. This runs in a browser, and the download name is a hint the user can change.

Source: https://github.com/mholt/PapaParse/issues/175

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents