Home > Code > Javascript > Print content of Div tag using Javascript

Print content of Div tag using Javascript

by Thamil   on Sep 30, 2014   Category: Javascript   |  Views: 1361    |  Points: 25   |  Gold 


Below java script code snippet is used to print the specific content of div in the page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Learn.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">

<script language="javascript" type="text/javascript">
function printPage(div)
{
var data = document.getElementById(div).innerHTML;
var printwindow = window.open('', '_blank', 'height=400,width=600');
printwindow.document.write('<html><body>' + data + '</body></html>');
printwindow.document.close();
printwindow.print();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="printArea" style="width: 100%; background-color: Gray; height: 75px">
test Print
</div>
<div id="Div1" style="width: 100%; background-color: Purple; height: 75px">
test print1
</div>
<asp:Button ID="Button1" runat="server" OnClientClick="javascript:printPage('printArea');" Text="Button" />
</div>
</form>
</body>
</html>




Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts