download-attribute-polyfill
Will polyfill the functionality of:
↓ ↓ ↓
<a href="/somefile.pdf" download>
Download this (don't navigate to it)
</a>
in IE11, which doesn't support it. This polyfill is small and works fast.
Usage
Install using npm:
npm i -S download-attribute-polyfill
And include it in your JavaScript somewhere:
import 'download-attribute-polyfill';
This polyfill automatically does its work. It will:
- Detect if polyfilling is needed (and otherwise won't do anything)
- Detect on click if it's on a link with the
download
attribute - Prevent their default behaviour
- Via an
XMLHttpRequest
, request the resource and create a blob of data - Instruct IE11 to download that data using
msSaveBlob