IE浏览器获取文本流然后导出不了
2019-02-19 本文已影响0人
爱笑的小白菜
导出不了是因为a标签的.download属性IE不支持,,以下为解决了的兼容写法:
function downLoad(content, filename) {//content是获取到的文本流, filename是导出的文件名,如:'项目管理.xlsx'
var blob = new Blob([content], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename);
} else {
var eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
eleLink.href = URL.createObjectURL(blob);
document.body.appendChild(eleLink);
eleLink.click();
document.body.removeChild(eleLink);
window.URL.revokeObjectURL(eleLink.href);
}
}