我希望有一个标记(锚点),点击后会触发下载。
我已经尝试过这个S / O问题中的所有解决方案以及更多: How to trigger a file download when clicking an html button or javascript并且不起作用,除了这个:
<a href="lorem.gif" download="lorem.gif">HTML 5 Download</a>
这个适用于某些文件类型的最新版本的Firefox和Chrome,如图片,但doesn't work for PDFs and it doesn't work on IE和许多其他浏览器。
答案 0 :(得分:1)
您正在寻找Content-Disposition
HTTP标头。您在发送文件时在服务器端设置它:
Content-Disposition: attachment; filename=lorem.pdf;
它基本上告诉浏览器他们应该下载文件而不是尝试渲染它。请参阅this SO question或此维基百科页面:MIME#Content-Disposition。
答案 1 :(得分:0)
Hrere是如何下载文件的
<a href="lorem.gif" download="lorem.gif"><button>Download</button></a>