简体   繁体   中英

Is it possible to make a download link for file on remote server?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM