안녕하세요 저는 자바스크립트를 공부하는 취준생입니다. <div><span style="font-size:9pt;">csv파일을 .html이 있는 루트폴더에 다운받고싶은데 그 방법이 구글링을해도 나오지 않네요 ㅠㅠ</span></div> <div><span style="font-size:9pt;"><br></span></div> <div><span style="font-size:9pt;">===========================================================================</span></div> <div><span style="font-size:9pt;"><br></span></div> <div><span style="color:#010101;font-family:Consolas, 'liberation mono', Menlo, Courier, monospace;white-space:pre;">downloadCsv(</span><span class="cs-default-common-string" style="color:#63a35c;font-family:Consolas, 'liberation mono', Menlo, Courier, monospace;white-space:pre;">"홍길동,1,2,3\r\n홍길동2,1,2,3"</span><span style="color:#010101;font-family:Consolas, 'liberation mono', Menlo, Courier, monospace;white-space:pre;">, </span><span class="cs-default-common-string" style="color:#63a35c;font-family:Consolas, 'liberation mono', Menlo, Courier, monospace;white-space:pre;">"test.csv"</span><span style="color:#010101;font-family:Consolas, 'liberation mono', Menlo, Courier, monospace;white-space:pre;">);</span></div> <div><pre class="ce-code-text" style="font-family:Consolas, 'liberation mono', Menlo, Courier, monospace;white-space:pre-wrap;width:878px;height:593px;border:0px;margin-top:0px;margin-bottom:0px;padding:10px 0px;color:#010101;"></pre><div style="white-space:pre;height:14px;padding:0px 7px;"><span class="cs-default-common-keyword1" style="color:#a71d5d;">function</span> downloadCsv(datas, <span class="cs-default-common-keyword0" style="color:#066de2;">name</span>){</div><div style="white-space:pre;height:14px;padding:0px 7px;"> <span class="cs-default-common-keyword1" style="color:#a71d5d;">var</span> encodedUri <span class="cs-default-common-keyword2" style="color:#0086b3;"></span><span class="cs-default-common-keyword1" style="color:#a71d5d;">=</span> encodeURIComponent(datas);</div><div style="white-space:pre;height:14px;padding:0px 7px;"> <span class="cs-default-common-keyword1" style="color:#a71d5d;">var</span> link <span class="cs-default-common-keyword2" style="color:#0086b3;"></span><span class="cs-default-common-keyword1" style="color:#a71d5d;">=</span> <span class="cs-default-common-keyword0" style="color:#066de2;">document</span>.createElement(<span class="cs-default-common-string" style="color:#63a35c;">"a"</span>);</div><div style="white-space:pre;height:14px;padding:0px 7px;"> link.setAttribute(<span class="cs-default-common-string" style="color:#63a35c;">"href"</span>, <span class="cs-default-common-string" style="color:#63a35c;">"data:text/csv;charset=utf-8,\uFEFF"</span> <span class="cs-default-common-keyword2" style="color:#0086b3;"></span><span class="cs-default-common-keyword1" style="color:#a71d5d;">+</span> encodedUri);</div><div style="white-space:pre;height:14px;padding:0px 7px;"> link.setAttribute(<span class="cs-default-common-string" style="color:#63a35c;">"download"</span>,<span class="cs-default-common-keyword0" style="color:#066de2;">name</span>);</div><div style="white-space:pre;height:14px;padding:0px 7px;"> link.click();</div><div style="white-space:pre;height:14px;padding:0px 7px;"> }</div><div style="white-space:pre;height:14px;padding:0px 7px;"><span style="font-size:9pt;"><br></span></div><div style="white-space:pre;height:14px;padding:0px 7px;"><span style="font-size:9pt;">=====================================================================================</span></div><div style="white-space:pre;height:14px;padding:0px 7px;"><br></div><div style="white-space:pre;height:14px;padding:0px 7px;">위의 코드를 실행시키면 csv파일이 무조건 윈도우의 다운로드 폴더에 저장되더라구요.</div><div style="white-space:pre;height:14px;padding:0px 7px;">혹시나 해서 name부분의 값을 "./test.csv"로 바꿔서 넣어봤지만 그대로 다운로드 폴더에 </div><div style="white-space:pre;height:14px;padding:0px 7px;">"_test.csv"라는 이름으로 <span style="font-size:9pt;">다운로드 되었습니다...</span></div><div style="white-space:pre;height:14px;padding:0px 7px;"><br></div><div style="white-space:pre;height:14px;padding:0px 7px;">이걸 루트폴더에 저장시키려면 어떤식으로 코드를 짜야 할까요?</div></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.