Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Created January 6, 2020 15:22
Show Gist options
  • Save johnmmoss/76d846208d74ad4dbe23ec9d5f0d5f29 to your computer and use it in GitHub Desktop.
Save johnmmoss/76d846208d74ad4dbe23ec9d5f0d5f29 to your computer and use it in GitHub Desktop.
Create a link and click it then remove link. Used for fudging browser file downloads
const downloadFile = (filename, text) => {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment