Saturday 14 December 2013

Print a Web Page Using JavaScript in client side

                                                         HTML Program
 -------------------------------------------------------------------------------------------------------------
Many times you would like to give a button at your webpage to print out the content of that web page via an actual printer.
JavaScript helps you to implement this functionality using print function of window object.
The JavaScript print function window.print() will print the current web page when executed. You can call this function directly using onclick event as follows:
--------------------------------------------------------------------------------------------------------------
<head>        
<title>
  
  Print a Web Page Using JavaScript
</title>

<!-- Print screen java script source code -->

<script language="JavaScript" type="text/JavaScript">

function disablePrintButton()
{
    document.getElementById('showPrintButton').style.display="none";
    window.print();
    document.getElementById('showPrintButton').style.display="block";
}
</script>
</head>
<body>
<table>
<center>
        <font face=verdana,arial,helvetica size=5 color="#000aa4"><b>Print a Web Page Using JavaScript</b></font>
</center>         <hr width=100%>
<p>
<center>
<font face=verdana,arial,helvetica size="1">
<p>&copy;2013 S.Manikandan<br>
All Rights Reserved
<p>This page last modified on Sat day, 14-Dec-2013 16:52:27 Pm
<p>http://selvanmani.blogspot.in/
<P>E-Mail : selvanmanieee@gmail.com</p>
<p>
</font>
<!-- Print screen java script source code -->

<tr>
    <td colspan="2"  class="button_row_center" id="showPrintButton">
    <INPUT name=button type=button
                    class=button_Class onclick="javascript:disablePrintButton();" value=Print>                  
    <input type="button" value="Close" onClick="window.close()" class="button_class"></td>
</tr>
</center>
</table>
</body>

</html>
--------------------------------------------------------------------------------------------------------------
source code



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

ScreenShot
 



Print a Web Page Using JavaScript
Print a Web Page Using JavaScript

©2013 S.Manikandan
All Rights Reserved This page last modified on Sat day, 14-Dec-2013 16:52:27 Pm http://selvanmani.blogspot.in/ E-Mail : selvanmanieee@gmail.com