用javascript编写的代码以CSV格式下载数据。这在FF,Chrome浏览器中工作正常。但在Safari中显示Type Error &#34; TypeError:&#39; [object BlobConstructor]&#39;不是构造函数(评估&#39; new Blob([csv],{type:&#39; text / csv; charset = utf-8;&#39;})&#39;)&#34; < / p>
我试图在所有论坛中解决这个问题。但没有成功。
我遵循的代码:
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename);
} else {
const link = document.createElement('a');
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', filename);
link.style = 'visibility:hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
欢迎提出建议和解决方案。