兼容IE下载文件

fetch(url,options).then(res => res.blob().then((blob)=>{

  if(window.navigator.msSaveOrOpenBlob){//兼容IE下载

    try{

      window.navigator.msSaveOrOpenBlob(blob,fileName)

    }cath(e){

      console.log(e)

    }

  }else{

    const a = document.createElement('a')

    const fileUrl = window.URL.createObjectURL(blob)

    a.href = fileUrl

    a.download = fileName

    document.body.appendChild(a)

    a.click()

    window.URL.revokeObjectURL(url)

    document.body.removeChild(a)

  }

})).catch((e)=>{})

posted @ 2022-01-05 10:45  riverslake  阅读(68)  评论(0)    收藏  举报