火狐浏览器下载 Excel 为什么没有后缀(文件名没有空格)
这个样子
const link = document.createElement('a')
link.href = data //设定下载链接地址
link.download = name //设定下载的文件名
alert(name)
link.style.display = "none"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
或者下面这样,都不行啊。
downloadFile(fileName, content) {
const blob = this.base64ToBlob(content);
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, fileName);
} else {
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
const evt = document.createEvent("MouseEvents");
evt.initEvent("click", false, false);
link.dispatchEvent(evt);
document.body.removeChild(link);
}
},
base64ToBlob(code) {
const parts = code.split(';base64,');
const contentType = parts[0].split(':')[1];
const raw = window.atob(parts[1]);
const rawLength = raw.length;
const uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array],{type:contentType});
},