How to print part of the content defined in a web page
Under normal circumstances, printing is to use window.print(); directly print the entire page, but if you need to print part of the content defined in the web page, you can use the following methods:
1. Add JavaScript to the code header of the page:
Code:
< script language=javascript>function doPrint() {bdhtml=window.document.body.innerHTML;sprnstr="<!-- startprint-->";eprnstr="<!-- endprint-->";prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));window.document.body.innerHTML=prnhtml;window.print();}</script>
2. Add it in the body of the page
<!-- startprint--AND!-- endprint-->
Logo.
That is, attach it to the html corresponding to the body that needs the user to print and save. At the same time, if you use a thief program to obtain remote data and need to print it, you can place the data within the definition label.
3. The interception of the content has been completed. Now add a link to "print":
code:
< a href=" javascript:;" onClick=" doPrint()"> Print</a>
----------------------------------------------------------------
From: A Jun Blog
Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/How-to-print-part-of-the-content-defined-in-a-web-page.htm