How to implement the page printing in JavaScript

In this article we will discuss about how to get the page printed in JavaScript.
  • 2198

We can print the web page that we have open while going to be executed using JavaScript and it is possible by using the print function of the window object of JavaScript. In the other words, by calling window.print() function direct on the onclick event we can print out the current page when executed.

JavaScript Code:

<head>

    <script type="text/javascript">

<!--

//-->

    </script>

</head>

<body>

    <form>

    <input type="button" value="Printout" onclick="window.print()" />

    </form>

</body>

Output:

 Image32.jpg

This application will generate a button by clicking on it we can print this page.

Ask Your Question 

Got a programming related question? You may want to post your question here
 
© 2020 DotNetHeaven. All rights reserved.