1function download(filename, text) {
2 var element = document.createElement('a');
3 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
4 element.setAttribute('download', filename);
5
6 element.style.display = 'none';
7 document.body.appendChild(element);
8
9 element.click();
10
11 document.body.removeChild(element);
12}
13
14// Start file download.
15download("hello.txt","This is the content of my file :)");
16