Skip to content

Instantly share code, notes, and snippets.

@hamxiaoz hamxiaoz/save.js

Created Jul 26, 2015
Embed
What would you like to do?
A way to generate and download CSV files client-side
// https://github.com/mholt/PapaParse/issues/175
var blob = new Blob([csvString]);
if (window.navigator.msSaveOrOpenBlob) // IE hack; see http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx
window.navigator.msSaveBlob(blob, "filename.csv");
else
{
var a = window.document.createElement("a");
a.href = window.URL.createObjectURL(blob, {type: "text/plain"});
a.download = "filename.csv";
document.body.appendChild(a);
a.click(); // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
document.body.removeChild(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.