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);
原文地址:https://www.cnblogs.com/jellyz/p/12737265.html