JS Control Web Printing (local printing) method finishing

Source: Internet
Author: User

  Define CSS styles first:  

The   code is as follows: @media print { . noprint {display:none;color:green} }    for content that you do not want to print only in the label plus CLASS=NOPR int can be printed when the customer will not see any changes to the page.   When printing call Window.print ();    Several other JS local printing methods:  deceitful Act:  printing, the need to print the content to replace the entire body content (the user will be in print when the change to see, The customer experience is not very good)     code is as follows: Function preview (oper)   ... {  if (Oper < 10) ... {  bdhtml=window.document.body.innerhtml;//Gets 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); Take the html  prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR)) back from the start code;//forward from the end code html  window.document.body.innerhtml=prnhtml;  window.print ();  window.document.body.innerhtml=bdhtml;  } else ... {  window.print (); } }    Use simple to add the content to be printed on the page to the middle <!--startprint1-->xxxxx<!-- endprint1-->  Add a Print button Onclick=preview (1)  -----------------------------------------  WebBrowser is a built-in browser control for IE without user downloads. (not experimented)   One, WebBrowser control   code as follows: <object id= ' WebBrowser ' width=0 height=0 classid= ' clsid:8856f961-340a-11d0-a96b-00c04fd705a2 ' ></object>    II , Webbrowder control methods     code as follows://print   WEBBROWSER1.EXECWB (6,1); //Print Setup   WEBBROWSER1.EXECWB (8,1);  //Print preview   WEBBROWSER1.EXECWB (7,1);    There are other uses for this component, listed below:  WEBBROWSER.EXECWB (1,1) Open   WEB.EXECWB (2,1) closes all the IE windows now and opens a new window   WEB.EXECWB (4,1) save page   WEB.EXECWB (6,1) print   WEB.EXECWB (7,1) Print preview   WEB.EXECWB (8,1) print page setup   WEB.EXECWB (10,1) view page Properties   WEB.EXECWB (15,1) It seems to be withdrawn, to be confirmed   WEB.EXECWB (17,1) Select all   WEB.EXECWB (22,1) Refresh   WEB.EXECWB (45,1) Close the form without prompting   but printing will print out the entire page, there is something printed on the page, we sometimes just need to print data tables, Then we're going to write a style: hide the parts that you don't want to print:  style content:    code as follows: <style type= "Text/css" media=print> . noprint ...... {display:none}  </style>    Then use styles to:  <p class= "noprint" > do not need to print the local </p>  code below:  <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? ')) ...... {  WB.EXECWB (6,6)  } }  </script>  <object classid= "CLSID : 8856f961-340a-11d0-a96b-00c04fd705a2 "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.