msSaveBlob在IE中不起作用

时间:2018-08-29 11:38:38

标签: javascript angular download navigator

我正在尝试保存从客户端计算机上的服务器收到的文件。这在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);
 }

0 个答案:

没有答案