zoukankan      html  css  js  c++  java
  • 多种打印方式

    <input class="Noprn" type="button" onclick="window.print()" value="打印"/>
      <input type="button" name="print" value="预览并打印" onclick="preview()"/>
      <input type="button" id="bt" onclick="javascript:printpage('myDiv')" value="DIV打印" />

    <script language="javascript" type="text/javascript">
      var HKEY_Root, HKEY_Path, HKEY_Key;
      HKEY_Root = "HKEY_CURRENT_USER";
      HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      //设置网页打印的页眉页脚为空 
      function PageSetup_Null() {
      try {
      var Wsh = new ActiveXObject("WScript.Shell");
      HKEY_Key = "header";
      Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
      HKEY_Key = "footer";
      Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
      }
      catch (e)
    { }
      }
    // //设置网页打印的页眉页脚为默认值 
    // function PageSetup_Default() {
    // try {
    // var Wsh = new ActiveXObject("WScript.Shell");
    // HKEY_Key = "header";
    // Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "&w&b页码,&p/&P");
    // HKEY_Key = "footer";
    // Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "&u&b&d");
    // }
    // catch (e)
    //{ }
    // }
    // PageSetup_Default(); 
    </script>
    <script language="javascript" type="text/javascript">

      function printpage(myDiv){ //DIV控制打印
       
      //var newstr = document.all.item(myDiv).innerHTML; 
      var newstr = document.getElementById(myDiv).innerHTML;
    // alert(newstr);
      var oldstr = document.body.innerHTML; 
      document.body.innerHTML = newstr; 
      window.print(); 
      document.body.innerHTML = oldstr; 
      return false; 
      } 
      </script>
    <script language="Javascript">
    function preview() {
      PageSetup_Null();
      bdhtml=window.document.body.innerHTML;
      sprnstr="<!--startprint-->";
      eprnstr="<!--endprint-->";
      prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
      prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
      window.document.body.innerHTML=prnhtml;
      window.print();
    }
    </script>

  • 相关阅读:
    解决PKIX:unable to find valid certification path to requested target 的问题
    Linux 上的常用文件传输方式介绍与比较
    用VNC远程图形化连接Linux桌面的配置方法
    红帽中出现”This system is not registered with RHN”的解决方案
    linux安装时出现your cpu does not support long mode的解决方法
    CentOS SSH配置
    es6扩展运算符及rest运算符总结
    es6解构赋值总结
    tortoisegit安装、clon、推送
    es6环境搭建
  • 原文地址:https://www.cnblogs.com/12go/p/2304990.html
Copyright © 2011-2022 走看看