应用scriptx的factory实现打印

昨晚应用IE自带的控件实现了打印,有一些东西老不是怎样如意。今天,用factory再次实现WEB打印。

1、插入CSS

  1. <style media="print">
  2. .noprint{display:none;}
  3. .pagenext{page-break-after: always;}
  4. .bgcolor {
  5. &nbsp;background-color: #CCCCCC;
  6. }
  7. </style>

2、插入JS

  1. <script defer>
  2. function setInstallStyles(fOK) {
  3.     document.getElementById("installFailure").runtimeStyle.display = fOK ? "none" : "block";
  4.     document.getElementById("Main").runtimeStyle.display = fOK ? "block" : "none";
  5. }
  6. function okInstall() {
  7.     setInstallStyles(true);
  8. }
  9. function noInstall() {
  10.     setInstallStyles(false);
  11. }
  12.  
  13. function viewinit() {
  14.   if (!factory.object) {
  15.       noInstall();
  16.       return
  17.   } else {
  18.   okInstall();
  19.   factory.printing.header = ""
  20.   factory.printing.footer = ""
  21.   factory.printing.portrait = false
  22.   factory.printing.leftMargin = 0.75
  23.   factory.printing.topMargin = 0.75
  24.   factory.printing.rightMargin = 0.75
  25.   factory.printing.bottomMargin = 0.75
  26.  
  27.  
  28.   // enable control buttons
  29.   var templateSupported = factory.printing.IsTemplateSupported();
  30.   var controls = idControls.all.tags("input");
  31.   for ( i = 0; i < controls.length; i++ ) {
  32.     controls[i].disabled = false;
  33.     if ( templateSupported && controls[i].className == "ie55" )
  34.       controls[i].style.display = "inline";
  35.     }
  36.   }
  37. }
  38. </script>

3、在页面加载的时候初始化插件

  1. <body onload="viewinit()">

4、插入插件

  1. <object id="factory" style="display:none" viewastext classid="clsid:1663ED61-23EB-11D2-B92F-008048FDD814" codebase="http://www.meadroid.com/scriptx/smsx.cab#Version=6,3,435,20">
  2. </object>

5、不打印部分

  1. <center class="noprint" id=idControls>
  2. <p>
  3. <input type=button class="button" value="打印本页" onclick="factory.printing.Print(false)">
  4. <input type=button class="button" value="页面设置" onclick="factory.printing.PageSetup()">
  5. <input type=button class="button" value="打印预览" onclick="factory.printing.Preview()">
  6. </p>
  7. </center>

6、插入没有安装插件显示代码

  1. <div id="installFailure" class="noprint" style="display:none">
  2. <h2>It appears ScriptX is unavailable or has failed to install.</h2>
  3. <p><b>Has the Infobar appeared?</b></p>
  4. <p>If you are using Internet Explorer 6 or later on Windows XP SP2 or later then the Explorer Information bar may appear while trying to install ScriptX, it looks like this:</p>
  5. <p style="padding: 4px"><img src="../images/infobar.png"></p>
  6. <p>If the bar has appeared, follow the instructions: click on the bar and then select <i>Install ActiveX Control...</i></p>
  7. <p><b>Are you an administrator?</b></p>
  8. <p>ScriptX is code that requires you have administrator rights on your machine in order to install it successfully.</p>
  9. <p>If you are not an administrator, please contact your administrator and ask them to install ScriptX for you.</p>
  10. </div>

2 条评论 »

  1. Koctr said,

    四月 16, 2008 at 1:18 下午

    document.getElementById(“Main”)中的Main对应什么?
    已加你的MSN

  2. hey idiot buy mp3s only here! said,

    九月 4, 2009 at 9:50 下午

    hey idiot buy mp3s only here!…

    Very usefull. Thanks! hey idiot buy mp3s only here!…

RSS feed for comments on this post · TrackBack URL

发表评论

You must be logged in to post a comment.