JS Control Web Printing (local printing) method finishing _javascript Skills

Source: Internet
Author: User
First define the CSS style:
Copy Code code as follows:

@media Print {
. noprint {Display:none;color:green}

For content that you don't want to print, just add class=noprint to the label, and the customer won't see any changes to the page when you print it.
Call Window.print () when printing;

the other several JS local printing method:
Deceitful Act
When printing, replace the content that needs to be printed with the whole body content (the user will see the change when printing, the customer experience is not very good)
Copy Code code as follows:

Function Preview (OPER)
...... {
if (Oper < 10) ... {
bdhtml=window.document.body.innerhtml;//get the HTML code for the current page
Sprnstr= "<!--startprint" +oper+ "-->";/set the print start area
Eprnstr= "<!--endprint" +oper+ "-->";//Set Print End area
Prnhtml=bdhtml.substring (Bdhtml.indexof (SPRNSTR) +18); Fetching HTML backwards from the start code
Prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR));//forward HTML from end code
Window.print ();
} else ... {
Window.print ();

Use very simple to add the contents of the page to the middle <!--startprint1-->xxxxx<!--endprint1-->
Add a Print button Onclick=preview (1)
WebBrowser is an IE-built browser control that requires no user downloads. (not tested)
One, WebBrowser control
Copy Code code as follows:

<object id= ' WebBrowser ' width=0 height=0 classid= ' clsid:8856f961-340a-11d0-a96b-00c04fd705a2 ' ></object >

Methods of Webbrowder Control
Copy Code code as follows:

Print settings
Print Preview

There are other uses for this component, as listed below:
WEB.EXECWB (2,1) closes all of the IE windows now and opens a new window
WEB.EXECWB (4,1) Save Web page
WEB.EXECWB (6,1) printing
WEB.EXECWB (7,1) Print preview
WEB.EXECWB (8,1) print Page Setup
WEB.EXECWB (10,1) view page Properties
WEB.EXECWB (15,1) seems to be withdrawn, pending confirmation
WEB.EXECWB (17,1) Select all
WEB.EXECWB (22,1) Refresh
WEB.EXECWB (45,1) Close the form without prompting
But printing is going to print out the entire page, the page has something to print out, we sometimes just need to print data tables, then we will write a style: To hide the parts do not want to print:
Style content:
Copy Code code as follows:

<style type= "Text/css" media=print>
. Noprint ... {Display:none}

You can then use styles to:
<p class= "noprint" > where no printing is needed </p>
The code is as follows:
Copy Code code as follows:

<script language= "javascript" >
function Printsetup () ... {
///print Page Setup
WB.EXECWB (8,1);
Function PrintPreview () ... {
//print Page Preview
WB.EXECWB (7,1);
Function PrintIt ()
.... {
if (confirm) (' OK to print? ') ')) ...... {
<object classid= CLSID:8856F961-340A-11D0-A96B-00C04 FD705A2 "height=0 id=wb name=wb width=0></object>
<input type=button name=button_print value=" Print "class = "Noprint" onclick= "Javascript:printit ()" >
<input type=button name=button_setup value= "Print page Setup" class= " Noprint "onclick=" Javascript:printsetup (); >
<input type=button name=button_show value= "Print preview class=" noprint "onclick=" Javascript:printpreview (); " >

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.