*
**## 出现文件跨域下载问题 https 域名与http 文件 处理方案**(把图片 http 更换为https)
*
const toUrl = filePath.split('://')[1]
let prol = window.location.protocol
## ***处理pdf文件直接下载,不预览***
downPdf(fileName,filePath){
var ajax=new XMLHttpRequest()
ajax.open( 'GET', filePath, true)
ajax.setRequestHeader('Cache-Control','no-cache')
ajax.setRequestHeader('Access-Control-Allow-Origin', '*')
ajax.responseType = 'blob';
ajax.onload = e =>{
let res = e.target.response
let blob = new Blob([res])
let aLink = document.createElement("a")
aLink.download = fileName // 下载文件的名字
aLink.href = URL.createObjectURL(blob)
aLink.click()
}
ajax.send()
}
处理pdf文件直接下载,不预览
最新推荐文章于 2023-09-22 11:39:58 发布