Window. print can print web pages, but sometimes we only want to print specific controls or content. What should we do?
Window. print the specified div
First, we can put the content to be printed in the div, and then print it with the following code.
Copy codeThe Code is as follows:
<Html>
<Head>
<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>
</Head>
<Body>
// HTML Page
// Other content 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 you wouldn't like to print
// Other content you wouldn't like to print
</Body>
</Html>