function export(name, data) {
  var urlObject = window.URL || window.webkitURL || window
  var export_blob = new Blob([data])
  var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
  save_link.href = urlObject.createObjectURL(export_blob)
  save_link.download = name
  fakeClick(save_link)
},
function fakeClick(obj) {
  var ev = document.createEvent('MouseEvents')
  ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
  obj.dispatchEvent(ev)
}

export("test.txt", "hello world");

 posted on 2020-10-20 14:01  布诺  阅读(1981)  评论(0编辑  收藏  举报