Today, I am working on a contract signing table for a company. Their requirements need to be printed. So I searched a page for some printed code on the Internet and did not look at it at the beginning, get started directly.
Code:
<Script type = "text/javascript">
Function preview (preview)
{
If (then <10)
{
Bdhtml###doc ument. body. innerHTML; // obtain the html code of the current page
Sprnstr = "<! -- Startprint "+ print +" --> "; // you can specify the start area for printing.
Eprnstr = "<! -- Endprint "+ print +" --> "; // sets the print end area.
Prnhtml = bdhtml. substring (bdhtml. indexOf (sprnstr) + 18); // retrieves html from the start code
Prnhtml = prnhtml. substring (0, prnhtml. indexOf (eprnstr); // retrieves html from the end code
Too many Doc ument. body. innerHTML = prnhtml;
Window. print ();
Required parameter Doc ument. body. innerHTML = bdhtml;
}
Else
{
Window. print ();
}
}
However, I found that all the borders of the tables in the table could not be printed after I used them. I asked the Group experts for advice, the original background color and background image are not printed.
After modification, I wrote three classes with css to solve the problem. There was another problem in the test. The print in IE browser was no problem, but there was no table when I used partial printing, looking for bugs after a bit of depression
You can view the Page code to find out the difference between partial printing and full-page printing:
Observe the dig jscode repository Doc ument. body. innerHTML = prnhtml; the Code indicates that the code to be printed is obtained and assigned to the entire page code, but the code to be printed does not contain the body tag, therefore, the entire page is empty during local printing.
Modify as follows:
Function preview (preview)
{
If (then <10)
{
Bdhtml###doc ument. body. innerHTML; // obtain the html code of the current page
Sprnstr = "<! -- Startprint "+ print +" --> "; // you can specify the start area for printing.
Eprnstr = "<! -- Endprint "+ print +" --> "; // sets the print end area.
Prnhtml = bdhtml. substring (bdhtml. indexOf (sprnstr) + 18); // retrieves html from the start code
Prnhtml = prnhtml. substring (0, prnhtml. indexOf (eprnstr); // retrieves html from the end code
Required parameter Doc ument. body. innerHTML = "<body>" + prnhtml + "</body> ";
Window. print ();
Required parameter Doc ument. body. innerHTML = bdhtml;
}
Else
{
Window. print ();
}
}
The local print after adding the body is normal!
Source: blog