我正在尝试保存从客户端计算机上的服务器收到的文件。这在Chrome和Firefox中有效,但在IE中则无效。
const a = document.createElement('a');
document.body.appendChild(a);
const blob = new Blob([response], {type: 'application/vnd.ms-excel'}),
url = window.URL.createObjectURL(blob);
console.log(navigator);
if (navigator.appVersion.toString().indexOf('.NET') > 0 && window.navigator.msSaveBlob) { // For IE
console.log('from Explorer', window.navigator);
window.navigator.msSaveBlob(blob, 'UnitDetails' + this.apnNumber + '.xlsx');
}
else { // For Other browsers
a.href = url;
a.download = 'UnitDetails' + this.apnNumber + '.xlsx';
a.click();
window.URL.revokeObjectURL(url);
}