Summarize the JS printing methods for future reference.
I. Use JS built-in function Printing
Directly call Java code
Program code <a href = "javascript: window. Print ();"> Print </a>
Ii. iewebbrowser Components
Introduction
Code http://support.microsoft.com/default.aspx? SCID = kb % 3ben-us % 3bq267240 # top
Http://support.microsoft.com/kb/q247671/#appliesto
Java code
Program code <object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = webbrowser width = 0> </Object>
<Input name = button onclick = Document. All. webbrowser. execwb (1,1) type = button value = open>
<Input name = button onclick = Document. All. webbrowser. execwb (2, 1) type = button value = close all>
<Input name = button onclick = Document. All. webbrowser. execwb (4,1) type = button value = Save As>
<Input name = button onclick = Document. All. webbrowser. execwb (6, 1) type = button value = print>
<Input name = button onclick = Document. All. webbrowser. execwb (6, 6) type = button value = print directly>
<Input name = button onclick = Document. All. webbrowser. execwb (7,1) type = button value = print preview>
<Input name = button onclick = Document. All. webbrowser. execwb (8, 1) type = button value = page Settings>
<Input name = button onclick = Document. All. webbrowser. execwb (10, 1) type = button value = attribute>
<Input name = button onclick = Document. All. webbrowser. execwb (17,1) type = button value = select all>
<Input name = button onclick = Document. All. webbrowser. execwb (22, 1) type = button value = Refresh>
<Input name = button onclick = Document. All. webbrowser. execwb (45, 1) type = button value = close>
<Object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = webbrowser width = 0> </Object>
<Input name = button onclick = Document. All. webbrowser. execwb (1,1) type = button value = open>
<Input name = button onclick = Document. All. webbrowser. execwb (2, 1) type = button value = close all>
<Input name = button onclick = Document. All. webbrowser. execwb (4,1) type = button value = Save As>
<Input name = button onclick = Document. All. webbrowser. execwb (6, 1) type = button value = print>
<Input name = button onclick = Document. All. webbrowser. execwb (6, 6) type = button value = print directly>
<Input name = button onclick = Document. All. webbrowser. execwb (7,1) type = button value = print preview>
<Input name = button onclick = Document. All. webbrowser. execwb (8, 1) type = button value = page Settings>
<Input name = button onclick = Document. All. webbrowser. execwb (10, 1) type = button value = attribute>
<Input name = button onclick = Document. All. webbrowser. execwb (17,1) type = button value = select all>
<Input name = button onclick = Document. All. webbrowser. execwb (22, 1) type = button value = Refresh>
<Input name = button onclick = Document. All. webbrowser. execwb (45, 1) type = button value = close>
3. Use the scriptx. Cab Control
1. Download The scriptx. Cab Control
Program code official website http://www.meadroid.com/scriptx/index.asp
2. Use the object element to modify the value of codebase and classid.
The scriptx. Cab control is called here.
Java code
Show Hidden content <Object ID = "Factory" style = "display: none" codebase = "$ {rooturl} JS/smsx. cab # vversion = 6, 3, 435,20 "classid =" CLSID: 1663ed61-23eb-11d2-b92f-008048fdd814 "viewastext> </Object>
<Object ID = "Factory" style = "display: none" codebase = "$ {rooturl} JS/smsx. cab # vversion = 6, 3, 435,20 "classid =" CLSID: 1663ed61-23eb-11d2-b92f-008048fdd814 "viewastext> </Object>
This code is used to load the cab file. The clsid and codebase must correspond to the information in the downloaded cab. Otherwise, the component will be loaded incorrectly, as long as you use WinRAR to open the downloaded cab file and find that the extension is. INF file, and then open it, you can see.
3. Call the control script
Print. JS File
Java code
Program code function setprintbase (headertext, footertext, rooturl ){
// -- Advanced features, which has never been used and is awaiting confirmation.
// 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"
VaR header = (headertext = NULL | headertext = "")? 'Default head': headertext;
VaR footer = (footertext = NULL | footertext = "")? 'Character page': footertext;
Factory. Printing. header = "& B" + header + "& B ";
Factory. Printing. footer = "& B" + footer;
Factory. Printing. Portrait = true;
Factory. Printing. leftmargin = 10.00;
Factory. Printing. topmargin = 10.00;
Factory. Printing. rightmargin = 10.00;
Factory. Printing. bottommargin = 10.00;
}
Function setprintbase (headertext, footertext, rooturl ){
// -- Advanced features, which has never been used and is awaiting confirmation.
// 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"
VaR header = (headertext = NULL | headertext = "")? 'Default head': headertext;
VaR footer = (footertext = NULL | footertext = "")? 'Character page': footertext;
Factory. Printing. header = "& B" + header + "& B ";
Factory. Printing. footer = "& B" + footer;
Factory. Printing. Portrait = true;
Factory. Printing. leftmargin = 10.00;
Factory. Printing. topmargin = 10.00;
Factory. Printing. rightmargin = 10.00;
Factory. Printing. bottommargin = 10.00;
}
Java code example
Program code <% @ page contenttype = "text/html; charset = GBK" %>
<HTML>
<Head>
<Meta http-equiv = "imagetoolbar" content = "no">
<Script language = "JavaScript" src = "print. js"> </SCRIPT>
<Style media = "print">
. Noprint {display: none ;}
</Style>
<Title> Print test </title>
</Head>
<Object ID = "Factory" style = "display: none" codebase = "smsx. Cab # vversion = 6, 3, 435,20" classid = "CLSID: Hangzhou" viewastext> </Object>
<SCRIPT defer>
Function window. onload (){
Setprintbase ('header ', 'footer ');
}
</SCRIPT>
<Body topmargin = "0" leftmargin = "0" rightmargin = "0" bottommargin = "0" marginwidth = "0" marginheight = "0">
<Center class = "noprint">
<Input type = button value = "print" onclick = "factory. Printing. Print (true)">
<Input type = button value = "page setting" onclick = "factory. Printing. pagesetup ()">
<Input type = button value = "print preview" onclick = "factory. Printing. Preview ()">
<Input type = "button" value = "close" onclick = "window. Close ();">
</Center>
<Center>
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0">
<Tr> <TD align = "center"> <B> content </B> </TD> </tr>
</Table>
</Center>
</Body>
</Html>
<% @ Page contenttype = "text/html; charset = GBK" %>
Program code <HTML>
<Head>
<Meta http-equiv = "imagetoolbar" content = "no">
<Script language = "JavaScript" src = "print. js"> </SCRIPT>
<Style media = "print">
. Noprint {display: none ;}
</Style>
<Title> Print test </title>
</Head>
<Object ID = "Factory" style = "display: none" codebase = "smsx. Cab # vversion = 6, 3, 435,20" classid = "CLSID: Hangzhou" viewastext> </Object>
<SCRIPT defer>
Function window. onload (){
Setprintbase ('header ', 'footer ');
}
</SCRIPT>
<Body topmargin = "0" leftmargin = "0" rightmargin = "0" bottommargin = "0" marginwidth = "0" marginheight = "0">
<Center class = "noprint">
<Input type = button value = "print" onclick = "factory. Printing. Print (true)">
<Input type = button value = "page setting" onclick = "factory. Printing. pagesetup ()">
<Input type = button value = "print preview" onclick = "factory. Printing. Preview ()">
<Input type = "button" value = "close" onclick = "window. Close ();">
</Center>
<Center>
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0">
<Tr> <TD align = "center"> <B> content </B> </TD> </tr>
</Table>
</Center>
</Body>
</Html>
Iv. Comparison
1. Window. Print is easy to call, but its function is simple.
2. More powerful functions, but the use of iewebbrowser sometimes reports errors where JS has no permissions.
3. The scriptx control has powerful functions. Currently, this method is used.