JavaScript 文件流下载

var blob = new Blob(["hello,the world"], {
  type: 'text/plain'
});
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
a.setAttribute('download', "text");
a.click();
document.body.removeChild(a)
URL.revokeObjectURL(objectUrl);

 

posted @ 2020-04-20 13:35  JellyZ  阅读(248)  评论(0编辑  收藏  举报