Window.print can print Web pages, but sometimes we just want to print specific controls or content.
Window.print Print the specified div
First we can put the content to be printed in the Div, and then use the following code to print.
Copy Code code as follows:
<script language= "JavaScript" >
function Printdiv (PrintPage)
{
var headstr = "var footstr = "</body>";
var newstr = Document.All.Item (printpage). InnerHTML;
var oldstr = Document.body.innerHTML;
Document.body.innerHTML = Headstr+newstr+footstr;
Window.print ();
Document.body.innerHTML = Oldstr;
return false;
}
</script>
<title>div print</title>
<body>
HTML Page
Other content for you wouldn ' t like to print
<input name= "B_print" type= "button" class= "IPT" onclick= "Printdiv" (' Div_print '); "value=" Print >
<div id= "Div_print" >
<H1 style= "color:red" >the Div content which you want to print
</div>
Other content for you wouldn ' t like to print
Other content for you wouldn ' t like to print
</body>