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();Window print() Method Parameters
No parameters are required
Window print() Method Returns ValueThis function does not return anything
Window print() Method ExampleThis 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:
Explanationwindow.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 JavaScriptTo 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