테스트 사이트 - 개발 중인 베타 버전입니다

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

smt4u 5년 전 조회 3,722

[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개

채택된 답변
+20 포인트
B
5년 전

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

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

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

 

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

</p>

<p><?php</p>

<p>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']);</p>

<p>

 

view~ 에서 호출

</p>

<p><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></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변 감사합니다. ^^ 지금 휴가중이라 집에 도착하는데로 해보겠습니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인