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'就行了。

posted @ 2009-04-13 12:22  Z.W.  阅读(321)  评论(0编辑  收藏  举报