How to use “window.print()” function to print a page?


To print a page in JavaScript, use the window.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.

Example

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

Live Demo

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

Updated on: 16-Jun-2020

997 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements