Force to download image instead of opening url link to image [duplicate]

You may be bitten by the fact that Firefox and Chrome 65+ only support same-origin download links, probably as a security measure.

Source: https://caniuse.com/#feat=download (see “Known issues” tab)

The Web Hypertext Application Technology Working Group (WHATWG) recommends that in cross-origin scenarios (as in your example), the web server that is hosting the image/file in question needs to send a Content-Disposition HTTP header for download= to be honored.

Source: https://html.spec.whatwg.org/multipage/links.html#downloading-resources


In short:

You can only use <a download='...'></a> to force download of an image/file, if:

  1. the html and the image/file are hosted on the same domain,
    or
  2. the image/file is on a different domain, and that server also says it should be downloaded.

Leave a Comment