浏览器环境 js 写文件

来源:互联网 发布:java 邮件发送多人 编辑:程序博客网 时间:2024/06/06 20:43

主要利用两个接口 Blob 和 URL.createObjectURL(blob)

Blob 一个二进制文件的读写构造函数
URL.createObjectURL(blob) 创建文件的引用

function writeFile(fileName, content){    var a= document.createElement('a');    var blob = new Blob([content],{type:'text/plain'});    a.download = fileName;    a.href = URL.createObjectURL(blob);    a.click()    }
example :writeFile("2.txt","嘿嘿嘿 , js",)