How to Print from JavaScript HTML using window.print

Ever come across a need where you want to print the HTML form or page? This is possible using the JavaScript window.print() function. You can use this code with any control (like Button) and even any event (like onclick). This will simply bring up the printer options from your machine and then you can follow the normal procedure of printing.

Note - A printer must be configured on your machine.

window.print();

This will not directly print the page, similar to the way you do it on your machine. The printer options window will show and you can make adjustments and settings before actually printing the contents.


This is not an AI-generated article but is demonstrated by a human.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!