function isKakao() { const userAgent = navigator.userAgent || navigator.vendor || window.opera; // 모바일 장치의 User-Agent 문자열을 포함하는 패턴 return /kakaotalk/i.test(userAgent); } function downloadFile() { el_target = document.querySelector('select.target') el_name = document.querySelector('input.name') el_code = document.querySelector('select.code') el_tell = document.querySelector('input.tell') fetch('/', { method: 'POST', // POST 요청 설정 headers: { 'Content-Type': 'application/json', // 요청의 Content-Type 설정 }, body: JSON.stringify({'target': el_target.value, 'code':el_code.value, 'name':el_name.value, 'tell': el_tell.value }), }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.blob(); // 서버 응답을 Blob으로 처리 }) .then(blob => { // Blob을 다운로드할 수 있는 링크 생성 const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; //a.download = 'file.txt'; // 다운로드할 파일의 이름 설정 document.body.appendChild(a); // 링크를 문서에 추가 a.click(); // 링크 클릭하여 다운로드 시작 document.body.removeChild(a); // 링크 제거 window.URL.revokeObjectURL(url); // URL 객체 해제 }) .catch(error => { el_label = document.querySelector('label.result') el_label.textContent = '일치하는 견적이 없습니다.' console.error('Error downloading file:', error); }); } document.querySelector('button.find').addEventListener('click', function() { downloadFile() }) $(document).ready(function() { if (isKakao()) { var target_url = location.protocol + '//' + location.host location.href = 'kakaotalk://web/openExternal?url='+encodeURIComponent(target_url); } })