微信内置浏览器下载pdf的时候标题为null?
Sonder
2023-05-19
738字
2分钟
浏览 (1.1k)
![0.jpg](https://s2.loli.net/2023/05/19/vZ6RH5SwyXVlu14.jpg)
我的解决方法是:
function download (url, fileName) {
const x = new XMLHttpRequest()
x.responseType = 'blob'
x.open('GET', url, true)
x.send()
x.onload = () => {
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(x.response) // create download url
downloadElement.href = href
downloadElement.download = fileName // set filename (include suffix)
document.body.appendChild(downloadElement) // append <a>
downloadElement.click() // click download
document.body.removeChild(downloadElement) // remove <a>
window.URL.revokeObjectURL(href) // revoke blob
}
}
export { download }