zoukankan      html  css  js  c++  java
  • javascript调用ie打印机

    window.print()方法调用ie打印,但打印出来有页码和路径,所以需要用脚本修改注册表:

    var HKEY_Root,HKEY_Path,HKEY_Key;
        HKEY_Root = "HKEY_CURRENT_USER\\";
        HKEY_Path="Software\\Microsoft\\Internet Explorer\\PageSetup\\";
        window.onload=PageSetup_Null();
        window.unonload=PageSetup_Reset();
      function PageSetup_Null(){
      try{
       var Wsh = new ActiveXObject("WScript.Shell");
       HKEY_Key = "header";
       //Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);
       Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
       HKEY_Key = "footer";
       //Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);
       Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
       }
       catch(e){
       }
      }
      function PageSetup_Reset(){
      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){
         
       }
      }

    这样就行了,但要隐藏页面中的某些内容使之显示出来而不打印出来:导入两个样式表

    <link rel="stylesheet" href="/websys/bz/css/common.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="/websys/bz/css/print.css" type="text/css" media="print" />

    两个css:

    common.css内容如下:

    *.dd{
    display:block;
    }

    print.css内容如下:

    *.dd{
    display:none;
    }
    在我们需要隐藏的地方写上class='dd'就行了。

  • 相关阅读:
    一 基础--进制转化
    七牛云上传视频并截取第一帧为图片(js实现)
    FNScanner二维码接口openView自定义扫码Demo
    UIPickerView 模块示例demo
    vPlayer 模块Demo
    doT的高级用法及loadData的使用
    acmPush模块示例demo
    UIChatBox模块示例demo
    分享一款基于aui框架的图文发布界面
    基于js的APP多语言处理
  • 原文地址:https://www.cnblogs.com/zack/p/1434630.html
Copyright © 2011-2022 走看看