html5 download attribute를 활용한 file download ( ie, edge 포함)

html
<!DOCTYPE html>
<html>
<body>
  <a href="data:text/plain;charset=utf-8,'aaaaaaa'" download="aa.txt" id="aFi-file-download"></a>
  <script>
    function file_download(str, filename){
      var file = new Blob([str],{type: "text/plain;charset=utf-8"});
      if(window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveOrOpenBlob(file, filename);
      } else {
        document.getElementById("aFi-file-download").href= "data:text/plain;charset=utf-8," + str;
        document.getElementById("aFi-file-download").download = filename;
        document.getElementById("aFi-file-download").click();
      }
    }
  </script>
</body>
</html>
call
file_download("abc", "wiz.txt");

카테고리미분류

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다