This article shares the JS printing combination function for everyone, which is comprehensive for your reference. The specific content is as follows
1. Local printing - print wherever you want
Solution:
Hide the places you don't want to print
<style type="text/css" media=print>
.noprint{display : none }
Use it when paging
.PageNext{page-break-after: always;}
Then add: to the page elements you don't want to print, and it won't appear in the print and print preview.
Add the page where you want to: <div></div>.
</style>
Controlling where you don't want to print
<p>No printing required</p>
2. Reference construction
WebBrowser is a built-in browser control in IE, and no user download is required.
WebBrowser control
<object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>
Regarding the usage of this component, the following are listed:
WebBrowser.ExecWB(1,1) Open
Web.ExecWB(2,1) Close all IE windows now and open a new window
Web.ExecWB(4,1) Save the web page
Web.ExecWB(6,1) Print
Web.ExecWB(7,1) Print Preview
Web.ExecWB(8,1) Print page settings
Web.ExecWB(10,1) View page properties
Web.ExecWB(15,1) seems to be cancelled, and it is to be confirmed
Web.ExecWB(17,1) Select all
Web.ExecWB(22,1) Refresh
Web.ExecWB(45,1) Close the form silently
3. Example
<head><script language="javascript"> <style type="text/css" media=print>.noprint{display : none }</style>function printsetup(){ // Print page settings wb.execwb(8,1); } function printpreview(){ // Print page preview wb.execwb(7,1); } function printit() { if(confirm('Are you sure to print?')) { wb.execwb(6,6) } } </script></head> <body><p><OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" id="wb" name="wb"></OBJECT> <input type="button" name="button_print" value="Print" onclick="javascript:printit()" /> <input type="button" name="button_setup" value="Print page settings" onclick="javascript:printsetup();" /> <input type="button" name="button_show" value="Print preview" onclick="javascript:printpreview();" /> </p></body>3.JS implements simple page local printing
function preview(oper){ if (oper < 10){ bdhtml=window.document.body.innerHTML;//Get the html code of the current page sprnstr="<!--startprint"+oper+"-->";//Set the print start area eprnstr="<!--endprint"+oper+"-->";//Set the print end area prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //Get the html from the start code backwards from the start code prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//Get the html from the end code forward window.document.body.innerHTML=prnhtml; window.print(); window.document.body.innerHTML=bdhtml;} else { window.print(); }}It is very easy to use to add the content to print on the page to the middle<!--startprint1-->XXXX<!--endprint1-->
Add another print button onclick=preview(1)
4. Control the margins of "vertical hit", horizontal hit" and "pages.
(1) <script defer>
function SetPrintSettings() { // -- advanced features factory.printing.SetMarginMeasure(2) // measure margins in inches factory.SetPageRange(false, 1, 3) // need pages from 1 to 3 factory.printing.printer = "HP DeskJet 870C" factory.printing.copies = 2 factory.printing.collate = true factory.printing.paperSize = "A4" factory.printing.paperSource = "Manual feed" // -- basic features factory.printing.header = "This is MeadCo" factory.printing.footer = "Advanced Printing by ScriptX" factory.printing.portrait = false factory.printing.leftMargin = 1.0 factory.printing.topMargin = 1.0 factory.printing.rightMargin = 1.0 factory.printing.bottomMargin = 1.0 } </script> function preview(oper){ if (oper < 10){ bdhtml=window.document.body.innerHTML;//Get the html code of the current page sprnstr="<!--startprint"+oper+"-->";//Set the print start area eprnstr="<!--endprint"+oper+"-->";//Set the print end area prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //Get the html prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//Get the html window.document.body.innerHTML=prnhtml; window.print(); window.document.body.innerHTML=bdhtml;} else { window.print(); }}It is very easy to use to add the content to print on the page to the middle<!--startprint1-->XXXX<!--endprint1-->
Add another print button onclick=preview(1)
For more information about js printing function, click "JS Printing Function Summary" to learn
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.