티스토리 뷰

DEV/SCRIPT

[JS] 화면 PRINT

SBP 2023. 12. 8. 16:51

/**
* PRINT
* target : [{ id : '', type : ''}]
* title
*/
  function print(target, title){
        let pageContent = '' ;

        // CONTENT 생성
        target.forEach( function ( obj , index) {
            let targetId = obj.id;
            pageContent +=  $('#' + targetId).html();
        });

        // 팝업  
        let newWindow = window.open('', '', 'width=1024, height=600'),
              document = newWindow.document.open(),
              pageContent =
                  '<!DOCTYPE html>\n' +
                  '<html>\n' +
                  '<head>\n' +
                  '<meta charset="utf-8" />\n' +
                  '<link rel="stylesheet" type="text/css" href="./css/print.css">' +
                  '<title> ' + title +' </title>\n' +
                  '</head>\n' +
                  '<body> '+
                  '<div class="pageTitle"> <h2> ' + title + '</h2> </div>'+  
                  '\n\n' + pageContent + '\n</body>\n</html>';
              document.write(pageContent);
              document.close();
              
        // 팝업 열기(CSS 로딩을 위해 Timer)
        setTimeout(() => { newWindow.print(); }, 1000);
    }





'DEV > SCRIPT' 카테고리의 다른 글

JS : 호이스팅(Hoisting)  (0) 2025.06.09
[JS] COPY  (0) 2024.02.22
[JS] 배열 - 두 배열 합치기, 배열 평탄화, 배열 분할  (3) 2023.12.08
[JS] 소수점  (0) 2023.12.08
[JS] IS NULL, IS UNDEFINED  (4) 2023.12.08
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/11   »
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
글 보관함