Download a file by an anchor-element only. No more Content-Disposition!
In the past I used the HTTP header Content-Disposition
to instruct the browser to download a file. I ended up doing this because I knew of no other way for this.
Until today.
I discovered, that the anchor
-element has a download
attribute.
<a href="35567e83.pdf" download="report-2022.pdf">
Download Report
</a>
By clicking this link, the browser will download the file instead of linking to it and saves it as report-2022.pdf
.
The browser support for this attribute is pretty good with support by all major desktop and mobile browsers.
More details can be found at the MDN docs.