Skip to content

Instantly share code, notes, and snippets.

@tonY1883
Created July 31, 2017 09:13
Show Gist options
  • Save tonY1883/5bf8d52feb14420f7c8e25825da83d73 to your computer and use it in GitHub Desktop.
Save tonY1883/5bf8d52feb14420f7c8e25825da83d73 to your computer and use it in GitHub Desktop.
save a text file with js
function saveFile(text, filename, mime) {
var link = document.createElement('a');
link.setAttribute('download', filename);
link.href = window.URL.createObjectURL(new Blob([text], {type: mime}));
document.body.appendChild(link);
window.requestAnimationFrame(function () {
var event = new MouseEvent('click');
link.dispatchEvent(event);
document.body.removeChild(link);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment