Created
July 31, 2017 09:13
-
-
Save tonY1883/5bf8d52feb14420f7c8e25825da83d73 to your computer and use it in GitHub Desktop.
save a text file with js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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