How to print the content of current window using JavaScript ?

The task is to print the content of the current window by using the window.print() method in the document. It is used to open the Print Dialog Box to print the current document. It does not have any parameter value.

Syntax:

window.print()

Example: This example representing how to print the content of current window using JavaScript.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <h1>Hello GeeksForGeeks Users</h1>
  
    <h3>
        Print the content of the current 
        window using HTML and JavaScript
    </h3>
  
    <form>
        <input type="button" value="Print" 
            onclick="print_current_page()" />
    </form>
  
    <script type="text/javascript">
        function print_current_page() {
            window.print();
        }
    </script>
</body>
  
</html>

chevron_right


Before Clicking On Print Button:

After Clicking On Print Button:

Supported Browser are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safri

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.