Is it possible to create a download link for a remote file in plain HTML, or with JavaScript or jQuery?
The download
attribute doesn't seem to work for remote files in Chrome 73 or Firefox 66.
<a href="//amazon.com/ads.txt" download>ads.txt</a>
Is it possible to create a download link for a remote file in plain HTML, or with JavaScript or jQuery?
The download
attribute doesn't seem to work for remote files in Chrome 73 or Firefox 66.
<a href="//amazon.com/ads.txt" download>ads.txt</a>
No, the file URL must be on the same domain as the containing document, unless it's a blob:
or data:
URL:
- This attribute only works for same-origin URLs.
- Although HTTP(s) URLs need to be in the same-origin, blob: URLs and data: URLs are allowed so that content generated by JavaScript, such as pictures created in an image-editor Web app, can be downloaded.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes
As far as I know it's not possible. I would recommend using some sort of proxy-script on your server to overcome the cross-domains issues, like a simple PHP script. You can check referrer, add custom headers for content disposition etc
You can't do this client side.
The server hosting the resource you want to download can provide a Content-Disposition
response header which will trigger a download.
Content-Disposition: attachment; filename=ads.txt;