-
StackOverflow 文档
-
JavaScript 教程
-
文件 API,Blob 和 FileReaders
-
客户端使用 Blob 下载 csv
function downloadCsv() {
var blob = new Blob([csvString]);
if (window.navigator.msSaveOrOpenBlob){
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();
document.body.removeChild(a);
}
}
var string = "a1,a2,a3";
downloadCSV(string);
来源参考; https://github.com/mholt/PapaParse/issues/175