Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

"window.print()" 함수를 사용하여 페이지를 인쇄하는 방법은 무엇입니까?


JavaScript로 페이지를 인쇄하려면 window.print() 메소드를 사용하십시오. 인쇄를 위해 선택할 프린터와 같은 인쇄 옵션을 쉽게 설정할 수 있는 표준 대화 상자가 열립니다.

예시

다음 코드를 실행하여 페이지 인쇄 방법을 배울 수 있습니다. −

<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Click to Print</button>
      <script>
         function display() {
            window.print();
         }
      </script>
   </body>
</html>