How to Print from JavaScript HTML using window.print


Ever came 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.




Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.