首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ JavaScript / 文章详情

微信内置浏览器下载pdf的时候标题为null?

Sonder
2023-05-19
738字
2分钟
浏览 (1.1k)

0.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 }

原文地址在这里:点击这里,我的 GitHub工具箱 记录很多这样处理方法的笔记,有兴趣的铁铁可以看一下

下一篇 / vue3 移动端使用canvas手写签名

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)