ajax下载
<body> <button id="btn">下载</button> </body> <script> btn.onclick=()=>{ fetch("./download.pdf") .then(r=>{ return r.blob() }).then(res=>{ blob = URL.createObjectURL(res) let a = document.createElement("a") a.href = blob a.download = "PDF" document.body.appendChild(a) a.click() document.body.removeChild(a) URL.revokeObjectURL(blob) }) } </script>