How to print the content of current window using JavaScript ? (original) (raw)

Last Updated : 26 Jul, 2024

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 `

GeeksForGeeks - Print Page

Hello GeeksForGeeks Users

Print the content of the current window using HTML and JavaScript

This is a sample paragraph that will be included in the printed page. You can add more content here as needed.

<script>
    function printCurrentPage() {
        window.print();
    }

    // Add a listener for the beforeprint event
    window.addEventListener('beforeprint', function() {
        console.log('Printing started');
    });

    // Add a listener for the afterprint event
    window.addEventListener('afterprint', function() {
        console.log('Printing finished');
    });
</script>

`

**Output:

https://media.geeksforgeeks.org/wp-content/uploads/20240725220311/Print.mp4

Similar Reads