【发布时间】:2009-05-28 14:10:19
【问题描述】:
我正在使用 jQuery Table to CSV 插件。我已经更改了弹出窗口,以便它告诉浏览器下载 CSV 文件。
原来是:
function popup(data) {
var generator = window.open('', 'csv', 'height=400,width=600');
generator.document.write('<html><head><title>CSV</title>');
generator.document.write('</head><body >');
generator.document.write('<textArea cols=70 rows=15 wrap="off" >');
generator.document.write(data);
generator.document.write('</textArea>');
generator.document.write('</body></html>');
generator.document.close();
return true;
}
我已将其更改为:
function popup(data) {
window.location='data:text/csv;charset=utf8,' + encodeURIComponent(data);
return true;
}
它在大多数情况下都有效。它仍然需要您找到您的电子表格软件,并创建自己的文件名...因为它会创建一个奇怪的文件名(例如:14YuskG_.csv.part)。
有什么改进的建议吗?
【问题讨论】:
-
jQuery 表格到 CSV 插件:kunalbabre.com/projects/table2CSV.php,感谢 Kunal Babre
标签: javascript jquery