downloadFile:base64数据导出文件,文件下载

function downloadFile(filename, data){    
  let DownloadLink = document.createElement('a');

if ( DownloadLink ){
    document.body.appendChild(DownloadLink);

    DownloadLink.style = 'display: none';

    DownloadLink.download = filename;

    DownloadLink.href = data;

    if ( document.createEvent ){

      let DownloadEvt = document.createEvent('MouseEvents');

      DownloadEvt.initEvent('click', true, false);

      DownloadLink.dispatchEvent(DownloadEvt);

    }

    else if ( document.createEventObject )

      wnloadLink.fireEvent('onclick');

    else if (typeof DownloadLink.onclick == 'function' )

      DownloadLink.onclick();

    document.body.removeChild(DownloadLink);

  }
}
posted @ 2020-01-19 15:28  入坑的H  阅读(806)  评论(0编辑  收藏  举报