ODNZSL / nzsl-online

New Zealand Sign Language Dictionary
GNU General Public License v3.0
40 stars 11 forks source link

NZSL-138: Add a polyfill for cross-origin downloads by downloading as a Blob to link to #1503

Closed joshmcarthur closed 1 year ago

joshmcarthur commented 1 year ago

This pull request implements a simple polyfill to get around a restriction of a[download] links, which is that they can't download files from a different origin. To get around this, we fetch the href, read it as a blob, generate a URL to the blob, and then use this as the link href with the download attribute set. Because the blob is treated as a same-origin resource, the download is allowed to proceed.

For users without JS, this will be a progressive enhancement, since the href will continue to open in a new tab within the browser (rather than being downloaded).

https://user-images.githubusercontent.com/292020/226475767-9bb953f5-c21b-457c-9f68-cb002e22a07b.mp4