html
<!DOCTYPE html> <html> <body> <a href="data:text/plain;charset=utf-8,'aaaaaaa'" download="aa.txt" id="aFi-file-download"></a> <script> function file_download(str, filename){ var file = new Blob([str],{type: "text/plain;charset=utf-8"}); if(window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveOrOpenBlob(file, filename); } else { document.getElementById("aFi-file-download").href= "data:text/plain;charset=utf-8," + str; document.getElementById("aFi-file-download").download = filename; document.getElementById("aFi-file-download").click(); } } </script> </body> </html>
call
file_download("abc", "wiz.txt");