JavaScript | Window print() Method
Page print in JavaScript is a simple code in JavaScript used to print the content of the web pages.
- The print() method prints the contents of the current window.
- It basically opens Print dialog box which lets you choose between various printing options.
Syntax:
window.print()
Parameters: No parameters required
Returns: This function do not return anything
The following Javascript code shows a print button and then it shows the property of that webpage in a sheet in which you are going to print it.
The JavaScript print function window.print() is used here to perform the functionality.
Example :
<!DOCTYPE html> <html> <head> <title> HTML | DOM Window Print() method </title> <script type="text/javascript"> </script> </head> <body> <h2>HI GEEKSFORGEEKS USER'S</h2> <form> <input type="button" value="Print" onclick="window.print()" /> </form> </body> <html> |
Output :
But the web pages are not limited to text only. There are other things too in the webpages like images consisting of different colors, etc. Printing such pages can be done by the following ways :
- Make a copy of the page and leave out unwanted text and graphics, then link that to the printer-friendly page from the original. This means that the whole page will be printed as you have seen the page it will be printed as it is without any change in it, if you will see an advertisement it will also be printed in it
- If you do not want to keep an extra copy of a page, then you can mark your printable text using proper comments like PRINT STARTS HERE ….. PRINT ENDS HERE and then you can use PERL or any other script in the background to purge printable text and display for final printing. This means that the selected portion will be printed
Supported Browser: The browser supported by Window print() Method are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safri
Recommended Posts:
- Javascript | Window Blur() and Window Focus() Method
- Javascript | Window Open() & Window Close Method
- Javascript | Window scrollTo() Method
- Javascript | Window prompt() Method
- Javascript | Window confirm() Method
- JavaScript | Window getComputedStyle() Method
- JavaScript BOM | Window Screen
- JavaScript | Window innerWidth and innerHeight Properties
- How to close current tab in a browser window using JavaScript?
- How to check a webpage is loaded inside an iframe or into the browser window using JavaScript?
- Web Window API | Window locationbar property
- Web Window API | Window scrollbars property
- Print the content of a div element using JavaScript
- How to print the content of an object in JavaScript ?
- Print current day and time using HTML and JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



