2

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> 
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Rmy5
  • 527
  • 8
  • 21

3 Answers3

4

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

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

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

0

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;
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335