Normally, window. Print () is used to print the entire page. However, if you need to print part of the content defined in the web page, you can use the following method:
1. on the page CodeAdd JavaScript to the header:
JavaScript code
Copy codeThe Code is as follows: <script language = JavaScript>
Function doprint (){
Bdhtml###doc ument. Body. innerhtml;
Sprnstr = "<! -- Startprint --> ";
Eprnstr = "<! -- Endprint --> ";
Prnhtml = bdhtml. substr (bdhtml. indexof (sprnstr) 17 );
Prnhtml = prnhtml. substring (0, prnhtml. indexof (eprnstr ));
Too many Doc ument. Body. innerhtml = prnhtml;
Window. Print ();
}
</SCRIPT>
2. Add <! -- Startprint --> and <! -- Endprint --> ID.
That is, append it to the HTML corresponding to the text to be printed and saved by the user. At the same time, if you use thievesProgramObtain remote data and print it. You can place the data within the defined tag.
3. The part of the captured content has been completed. Add a "print" link:
<A href = "javascript:;" onclick = "doprint ()"> Print </a>