ScriptX use controls to achieve the IE browser page print function call browser js "Print" and "Print Preview

  Js talked about before calling ie browser comes with printing usage, using plug-ins today speak of the way. Can not control the browser comes with print margins, headers and footers and other options, especially if the printed page, it can not automatically be brought before a title page, it does not apply to print multiple pages of functions. Use ScriptX control can be the perfect solution to the problem collated printing, although this plug-in is a fee, but free and open features have been sufficient.

  First, download the plug-in , double click to execute the file, and then all the way next, the installation is complete.

  Add the following code in your document.

1 <OBJECT classid="CLSID:1663ED61-23EB-11D2-B92F-008048FDD814" height="0" id="wb" name="wb" width="0"></OBJECT>

  Briefly about the <object> tag, the function of this tag is embedded plug-ins, can be a java class, the software can be installed in the registry, the theory for the <object> tag can be embedded: images, audio, video, Flash, ActiveX Some other plugins, the above embodiment is inserted into an ActiveX plug-in, ActiveX ClassID is this ID in the registry, the registry can be opened, the search will find the ID values ​​are as follows:

 

  Yes, what we've just installed ScriptX control. The following is the major print js code, divided into "Print Preview", "Print" two functions. Print area style questions, please refer js call the browser "Print" and "Print Preview

  

1       // Print Preview 
2          function PrintPreview () {
 . 3              var userAgent = the navigator.userAgent; // made userAgent browser string 
. 4              IF (useragent.indexOf ( "the Chrome")> -1 || useragent.indexOf ( "Opera ")> -1 ) {
 . 5                  window.print ();
 . 6              } the else {
 . 7                  the try {   
 . 8                      var srcBody = window.document.body.innerHTML;
 . 9                      PrintBase ();
 10                      wb.printing.Preview ();
 . 11                     = window.document.body.innerHTML srcBody;
 12 is                      window.location.reload ();
 13 is                  } the catch (E) {
 14                      Alert ( "install the print widget" );
 15                  }
 16              }
 17          }
 18          // print 
. 19          function PrintHTML () {
 20 is              the try {
 21 is                  var srcBody = window.document.body.innerHTML;
 22 is                  PrintBase ();
 23 is                  window.print ();
 24                 = window.document.body.innerHTML srcBody;
 25                  window.location.reload ();
 26 is              } the catch (E) {
 27                  Alert ( "install the print widget" );
 28              }
 29          }

  HTML code is stored above operation at the time of preview or print, because you preview or print may modify the style pages, but we do should not change the page after the original style of these operations, so to recover.

  Set header and footer of js layout method: PrintBase ()

1  // Set print parameters 
2  function PrintBase (Sign) {
 . 3      var header = "" ;
 . 4      var footer = "" ;
 . 5      Sign = to false ;
 . 6      header = $ ( "# fromName") Val () + "Form Number. ". text () +:" + $ ( "# formno)" & b application date: "+ $ (" # CreateTime " ) .text ();
 . 7      footer =" & B total & P / page & p p " ;
 . 8  
. 9      = header wb.printing.header;    // header 
10      wb.printing.footer = footer;    // footer default & u & b & d &w- URL 
11      wb.printing.portrait = Sign;    //longitudinal printing true, false transverse print 
12 is      wb.printing.leftMargin =. 4 ;
 13 is      wb.printing.topMargin =. 8 ;
 14      wb.printing.rightMargin =. 4 ;
 15      wb.printing.bottomMargin =. 8 ;
 16 }

  ScriptX above is the use of plug-page print function to explain the main welcome message corrections or advice.

 

Guess you like

Origin www.cnblogs.com/chenboaixuexi/p/11954206.html