A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-window-print-method/ below:

JavaScript Window print() Method - GeeksforGeeks

JavaScript Window print() Method

Last Updated : 04 Mar, 2024

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. 

HTML
<!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:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4