1//javascript
2function download(text, name, type) {
3 var a = document.getElementById("a");
4 var file = new Blob([text], {type: type});
5 a.href = URL.createObjectURL(file);
6 a.download = name;
7}
8//html
9<a href="" id="a">click here to download your file</a>
10<button onclick="download('file text', 'myfilename.txt', 'text/plain')">Create file</button>