js前端base64转word并下载

代码如下
var raw = window.atob(ba);
var uInt8Array = new Uint8Array(raw.length);
for (var i = 0; i < raw.length; i++) {
  uInt8Array[i] = raw.charCodeAt(i);
}

const link = document.createElement("a");
const blob = new Blob([uInt8Array],{
  // type: 'application/vnd.ms-excel'
  type: 'application/msword'
})

link.style.display = 'none';
link.href = URL.createObjectURL(blob);
//link.setAttribute('download','对比结果_'+$scope.你的变量+'.xls');
link.setAttribute('download','对比结果');

document.body.appendChild(link)
link.click()

document.body.removeChild(link)

你可能感兴趣的:(js前端base64转word并下载)