用于创建 CSV 文件的导出功能在 Chrome 中不起作用
export function to create a CSV file does not work in Chrome
我创建了这个函数来导出一些数据。它是用 backbone.js 编写的 Web 应用程序。它在 Firefox 和 IE 中工作正常下载的文件具有扩展名 .csv 并且是文本 (text/csv) 但 Chrome 它在它说的文件的属性中没有任何扩展名是文本 (text/plain) 这也需要是文本 (text/csv) 并带有 .csv 扩展名。
export: function (ev) {
var blob = new Blob( [ ev.currentTarget.attributes.csv.nodeValue ], { type: "text/csv"} );
if ( navigator.msSaveOrOpenBlob ) {
navigator.msSaveOrOpenBlob( blob, "output.csv" );
} else {
window.open( "data:text/csv;charset=utf-8," + escape(ev.currentTarget.attributes.csv.nodeValue), '_blank')
return false;
}
},
我怎样才能做到这一点?
这对我有用。也许它对其他人有用
export: function (ev) {
var blob = new Blob( [ ev.currentTarget.attributes.csv.nodeValue ], { type: "text/csv;charset=utf8;"} );
console.log(999);
if ( navigator.msSaveOrOpenBlob ) {
navigator.msSaveOrOpenBlob( blob, "export.csv" );
} else {
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.setAttribute('download', 'export.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
return false;
}
},
我创建了这个函数来导出一些数据。它是用 backbone.js 编写的 Web 应用程序。它在 Firefox 和 IE 中工作正常下载的文件具有扩展名 .csv 并且是文本 (text/csv) 但 Chrome 它在它说的文件的属性中没有任何扩展名是文本 (text/plain) 这也需要是文本 (text/csv) 并带有 .csv 扩展名。
export: function (ev) {
var blob = new Blob( [ ev.currentTarget.attributes.csv.nodeValue ], { type: "text/csv"} );
if ( navigator.msSaveOrOpenBlob ) {
navigator.msSaveOrOpenBlob( blob, "output.csv" );
} else {
window.open( "data:text/csv;charset=utf-8," + escape(ev.currentTarget.attributes.csv.nodeValue), '_blank')
return false;
}
},
我怎样才能做到这一点?
这对我有用。也许它对其他人有用
export: function (ev) {
var blob = new Blob( [ ev.currentTarget.attributes.csv.nodeValue ], { type: "text/csv;charset=utf8;"} );
console.log(999);
if ( navigator.msSaveOrOpenBlob ) {
navigator.msSaveOrOpenBlob( blob, "export.csv" );
} else {
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.setAttribute('download', 'export.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
return false;
}
},