Open In App

JavaScript Window print() Method

The window.print() method in JavaScript is used to open the Print Dialog Box, which allows users to print the contents of the current window or document.

Window print() Method Syntax

window.print();

Window print() Method Parameters

No parameters are required



Window print() Method Returns Value

This function does not return anything

Window print() Method Example

This example shows a print button and then it shows the property of that webpage in a sheet in which you are going to print it. 






<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>
        JavaScript Window print() Method
    </title>
</head>
 
<body>
    <h2>HI GEEKSFORGEEKS USER'S</h2>
    <form>
        <input type="button"
               value="Print"
               onclick="window.print()" />
    </form>
</body>
 
</html>

Output:

Explanation

JavaScript Window print() Method – UseCases:

1. How to print the content of current window using JavaScript ?

window.print() method is used to open the Print Dialog Box to print the current document. It does not have any parameter value.

2. Print the content of a div element using JavaScript

To print a div’s content in JavaScript, store div content in a variable, then on button click, extract and write div content to a popup window, and print using window.print().

Supported Browsers:

Article Tags :