2018. 3. 19. 13:19 JavaScript/Util 함수
[JavaScript] IE11 Chrome txt 파일 다운로드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | download : function (filename, text) { if ( this .testBrowser === 'chrome' ) { var element = document.createElement( 'a' ); element.setAttribute( 'href' , 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute( 'download' , filename); element.style.display = 'none' ; document.body.appendChild(element); element.click(); document.body.removeChild(element); } else // IE Browser log Donwload { var a = document.createElement( "a" ), file = new Blob([text], { type: "text/plain;charset=utf-8" }); if (window.navigator.msSaveOrOpenBlob) // IE10+ window.navigator.msSaveOrOpenBlob(file, filename); else { // Others var url = URL.createObjectURL(file); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); setTimeout( function () { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); } } }, |
'JavaScript > Util 함수' 카테고리의 다른 글
[JavaScript - 자바스크립트] Object(오브젝트) 길이 구하기 (0) | 2018.04.09 |
---|---|
[JavaScript] JavaScript 브라우저 체크 (0) | 2018.03.19 |
[JavaScript] 자리수만큼 0 채워주기 (zeroPrint) (0) | 2018.03.19 |