Computer >> Computer tutorials >  >> Programming >> Javascript

How to print a page using JavaScript?


To print a page in JavaScript, use the print() method. It opens up the standard dialog box, through which you can easily set the printing options like which printer to select for printing.

Here’s an example −

How to print a page using JavaScript?

Example

You can try to run the following code to learn how to print a page −

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