Pages

Monday, 20 June 2011

Java Script function for Printing Div content.

1 comments
 

Hi Friends, in this post I would like to explain Java Script function for Printing Div content.

Here I took one Button control for printing the content.

JavaScript Function:

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

function Print(elementId)

{

var printContent = document.getElementById(elementId);

var windowUrl = 'about:blank';

var uniqueName = new Date();

var windowName = 'Print' + uniqueName.getTime();

var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

printWindow.document.write(printContent.innerHTML);

printWindow.document.close();

printWindow.focus();

printWindow.print();

printWindow.close();

}

script>

Div content:

<div id="printDivContent" >

Here we can place any content like controls,text……

div>

Calling div from the Button control:

<asp:Button ID="btnPrint" runat="server" onclientclick="javascript:Print('printDivContent');" Text="Print"

Width="50px" />

Thank You…

Shout it

One Response so far.

  1. Anonymous says:

    Thanks alot. Realy helpful

Leave a Reply