Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jelmerdemaat/dwnld-attr-polyfill
Polyfills the a[download] attribute
https://github.com/jelmerdemaat/dwnld-attr-polyfill
attribute download ie11 javascript polyfill
Last synced: 4 days ago
JSON representation
Polyfills the a[download] attribute
- Host: GitHub
- URL: https://github.com/jelmerdemaat/dwnld-attr-polyfill
- Owner: jelmerdemaat
- License: other
- Created: 2019-10-09T16:32:59.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T01:30:09.000Z (over 1 year ago)
- Last Synced: 2024-04-24T22:21:16.488Z (7 months ago)
- Topics: attribute, download, ie11, javascript, polyfill
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/dwnld-attr-polyfill
- Size: 1.58 MB
- Stars: 13
- Watchers: 2
- Forks: 4
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# dwnld-attr-polyfill
[GitHub](https://github.com/jelmerdemaat/dwnld-attr-polyfill) | [NPM](https://www.npmjs.com/package/dwnld-attr-polyfill) | [@jelmerdemaat](https://twitter.com/jelmerdemaat)
Will polyfill the functionality of the download attribute:
```html
↓ ↓ ↓
Download this (don't navigate to it)
```in IE11, [which doesn't support it](https://www.caniuse.com/#feat=download). This polyfill is **small** and works **fast**.
## Usage
Install using [npm](https://docs.npmjs.com/about-npm/):
```sh
npm i -S dwnld-attr-polyfill
```
And include it in your JavaScript somewhere:```sh
import 'dwnld-attr-polyfill';
```This polyfill automatically does its work. It will:
1. Detect if polyfilling is needed (and otherwise won't do anything)
2. Detect on click if it's on a link with the `download` attribute
3. Prevent their default behaviour
4. Via an `XMLHttpRequest`, request the resource and create a blob of data
5. Instruct IE11 to download that data using `msSaveBlob`### Why didn't you just use the word 'download' in the package name?
Because npm doesn't allow that:```
$ npm publish
npm ERR! 400 Bad Request - PUT https://registry.npmjs.org/download-attr-polyfill - That word is not allowed. Please contact support ([email protected]) if you believe you received this in error.
```