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

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

QA

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

답변 2

본문

[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>
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 0
© SIRSOFT
현재 페이지 제일 처음으로