엣지 브라우저에서 파일이 다운이 안됩니다.

엣지 브라우저에서 파일이 다운이 안됩니다.

QA

엣지 브라우저에서 파일이 다운이 안됩니다.

본문

[code]

<input type="text" id="wr_1" value="테스트"><!-- value="<?=$view['wr_1']?>" -->
<button type="button" onclick="save()">저장하기</button>
<script>
function save() {
  var obj = document.createElement('a');
  obj.setAttribute('href', 'data:text/plain;charset=utf-8,'+encodeURIComponent(document.querySelector('#wr_1').value));
  obj.setAttribute('download', 'wr_1.txt'); // DateTime 이용하면 좀 더 깔끔하겠죠?
  obj.style.display = 'none';
  document.body.appendChild(obj);
  obj.click();
  document.body.removeChild(obj);
}
</script>
[code]

 

크롬에서는 잘 되는데 옛날 엣지에서는 다운이 안됩니다.

혹시 옛날 엣지 브라우저 에서 다운 받을수 있는 방법 있을까요?

이 질문에 댓글 쓰기 :

답변 2

구 Edge를 버린지 오래라, 가상이라도 구축해서 테스트해보려니 불편해서 다른 방법 남깁니다.

그냥 주어진 문자열 그대로 파일로 다운받는 것이지만,

사용자(관리자) 체크 등의 코드를 넣으면 좀 더 낫겠죠? 기타 생략합니다.

 

down_txt.php - 그냥 아래처럼 단순한 파일 하나 만들고


<?php
if ( !isset($_GET['wr_1']) || !strlen($_GET['wr_1']) ) exit('<script>self.close();</script>');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="wr_1.txt"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: '.strlen($_GET['wr_1']));
exit($_GET['wr_1']);

 

view~ 에서 호출


<input type="text" id="wr_1" value="테스트">
<button type="button" onclick="save()">저장하기</button>
<script>
function save() {
  window.open('down_txt.php?wr_1='+encodeURIComponent(document.getElementById('wr_1').value));
}
</script>
답변을 작성하시기 전에 로그인 해주세요.
전체 123,528 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT