Open In App

How to print the content of current window using JavaScript ?

Last Updated : 15 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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()

Parameters: No parameters are required

Returns: This function does not return anything

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

html




<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>


Output:

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads