JS printing problem, urgent !!!!!

Source: Internet
Author: User

Summarize the JS printing methods for future reference.

I. Use JS built-in function Printing

Direct call
Java code replication code

1. <a href = "javascript: window. Print ();"> Print </a>

<A href = "javascript: window. Print ();"> Print </a>

Ii. iewebbrowser Components

Introduction

Http://support.microsoft.com/default.aspx? SCID = kb % 3ben-us % 3bq267240 # top
Http://support.microsoft.com/kb/q247671/#appliesto

Java code replication code

1. <object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = webbrowser width = 0> </Object>
2. <input name = button onclick = Document. All. webbrowser. execwb (1,1) type = button value = open>
3. <input name = button onclick = Document. All. webbrowser. execwb (2, 1) type = button value = close all>
4. <input name = button onclick = Document. All. webbrowser. execwb (4,1) type = button value = Save As>
5. <input name = button onclick = Document. All. webbrowser. execwb (6, 1) type = button value = print>
6. <input name = button onclick = Document. All. webbrowser. execwb (6, 6) type = button value = print directly>
7. <input name = button onclick = Document. All. webbrowser. execwb (7,1) type = button value = print preview>
8. <input name = button onclick = Document. All. webbrowser. execwb (8, 1) type = button value = page Settings>
9. <input name = button onclick = Document. All. webbrowser. execwb (10, 1) type = button value = property>
10. <input name = button onclick = Document. All. webbrowser. execwb (17,1) type = button value = select all>
11. <input name = button onclick = Document. All. webbrowser. execwb (22,1) type = button value = Refresh>
12. <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

Official 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 replication code

1. <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 replication code

1. Function setprintbase (headertext, footertext, rooturl ){
2.
3. // -- advanced features, which has never been used and is awaiting confirmation.
4.
5. // factory. Printing. setmarginmeasure (2); // measure margins in inches
6.
7. // factory. setpagerange (false, 1, 3); // need pages from 1 to 3
8.
9. // factory. Printing. Printer = "HP Deskjet 870c ";
10.
11. // factory. Printing. Copies = 2;
12.
13. // factory. Printing. collate = true;
14.
15. // factory. Printing. papersize = "A4 ";
16.
17. // factory. Printing. papersource = "manual feed"
18.
19. var header = (headertext = NULL | headertext = "")? 'Default head': headertext;
20.
21. var footer = (footertext = NULL | footertext = "")? 'Character page': footertext;
22.
23. Factory. Printing. header = "& B" + header + "& B ";
24.
25. Factory. Printing. footer = "& B" + footer;
26.
27. Factory. Printing. Portrait = true;
28.
29. Factory. Printing. leftmargin = 10.00;
30.
31. Factory. Printing. topmargin = 10.00;
32.
33. Factory. Printing. rightmargin = 10.00;
34.
35. Factory. Printing. bottommargin = 10.00;
36.
37 .}

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;

}

Example
Java code replication code

1. <% @ page contenttype = "text/html; charset = GBK" %>
2.
3. <HTML>
4. 5. <meta http-equiv = "imagetoolbar" content = "no">
6. <script language = "JavaScript" src = "print. js"> </SCRIPT>
7. <style media = "print">
8 .. noprint {display: none ;}
9. </style>
10. <title> Print test </title>
11. 12. <Object ID = "Factory" style = "display: none" codebase = "smsx. cab # vversion = 6, 3, 435,20 "classid =" CLSID: 1663ed61-23eb-11d2-b92f-008048fdd814 "viewastext> </Object>
13.
14. <SCRIPT defer>
15. function window. onload (){
16. setprintbase ('header ', 'footer ');
17 .}
18. </SCRIPT>
19. <body topmargin = "0" leftmargin = "0" rightmargin = "0" bottommargin = "0" marginwidth = "0" marginheight = "0">
20. <center class = "noprint">
21. <input type = button value = "print" onclick = "factory. Printing. Print (true)">
22. <input type = button value = "page setting" onclick = "factory. Printing. pagesetup ()">
23. <input type = button value = "print preview" onclick = "factory. Printing. Preview ()">
24. <input type = "button" value = "close" onclick = "window. Close ();">
25. </center>
26. <center>
27. <Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0">
28. <tr> <TD align = "center"> <B> content </B> </TD> </tr>
29. </table>
30. </center>
31. </body>
32.

<% @ 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>

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.

This is also good, there are printed to Word and Excel

Http://hi.baidu.com/afei0211/blog/item/20523955ca8bebc2b745ae98.html

Http://hi.baidu.com/hongz1125/blog/item/0152bcfd84ce1e1008244d5c.html

In the. NET environment
Http://blog.csdn.net/flygoldfish/archive/2004/08/17/77208.aspx

 

 

Other: http://hi.baidu.com/see7di/blog/item/7dca1a238bd3594f93580742.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.