<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<script language="javascript">
function printsetup()
{
  // 打印页面设置
  wb.execwb(8,1);
}
function printpreview()

   // 打印页面预览(直接关闭原来页面)
try
{
wb.ExecWB(7,1);
window.onfocus=function(){wb.ExecWB(45,1);}
window.opener=null;
}
catch(e)
{
window.close();
}
try{
window.close();
}
catch(e)
{
window.close();
}
}function printpreview1(){
  // 打印页面预览(不关闭原来页面)
  wb.execwb(7,1);
  }  
     
function printit()
{
   if (confirm('确定打印吗?')){
    wb.execwb(6,1)
}
}
</script><script language=javascript>
  //浮动帧打印
  function fudong() 
  {
   var odoc=window.document;
   var r=odoc.body.createTextRange();
   var stxt=r.htmlText;
   alert(stxt)
   var pwin=window.open("","print");
   pwin.document.write(stxt);
   pwin.print();
  }
</script><script language="VBScript">
  dim hkey_root,hkey_path,hkey_key
  hkey_root="HKEY_CURRENT_USER"
  hkey_path="\Software\Microsoft\Internet Explorer\PageSetup"  '//设置网页打印的页眉页脚为空
  function pagesetup_null()
    on error resume next
    Set RegWsh = CreateObject("WScript.Shell")
    hkey_key="\header"    
    RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
    hkey_key="\footer"
    RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
  end function  '//设置网页打印的页眉页脚为默认值
  function pagesetup_default()
    on error resume next
    Set RegWsh = CreateObject("WScript.Shell")
    hkey_key="\header"    
    RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"
    hkey_key="\footer"
    RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d"
  end function
</script>
</head>
<body><OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"height=0 id=wb name=wb width=0></OBJECT>
<input type=button name=button_print value="打印"onclick="javascript:printit()">
<input type=button name=button_print value="浮动帧打印"onclick="javascript:fudong()">
<input type=button name=button_setup value="打印页面设置"onclick="javascript:printsetup();">
<input type=button name=button_show value="打印预览-关闭原页"onclick="javascript:printpreview();">
<input type=button name=button_show value="打印预览-不关原页"onclick="javascript:printpreview1();">
<input type=button name=button_show value="页眉页脚为空"onclick="javascript:pagesetup_null();">
<input type=button name=button_show value="眉页脚为默认值"onclick="javascript:pagesetup_default();">
<input type=button name=button_fh value="关闭"onclick="javascript:window.close();">
<br>
WebBrowser.ExecWB(1,1) 打开
<br>
Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
<br>
Web.ExecWB(4,1) 保存网页(显示功能与SaveAs相同!)
<br>
Web.ExecWB(6,1) 打印
<br>
Web.ExecWB(7,1) 打印预览
<br>
Web.ExecWB(8,1) 打印页面设置
<br>
Web.ExecWB(10,1) 查看页面属性
<br>
Web.ExecWB(15,1) 好像是撤销,有待确认
<br>
Web.ExecWB(17,1) 全选
<br>
Web.ExecWB(22,1) 刷新
<br>
Web.ExecWB(45,1) 关闭窗体无提示
</BODY>
</HTML>

解决方案 »

  1.   

    我用的是JSP,
    VBscript能和JSP共存,并产生作用吗?
      

  2.   

    要改楼主说的东西是要改注册表的,不知楼主的打印是在客户端做还是服务端做?客户端的安全级别要降得很低才行,而且Norton这种东西会把改注册表的脚本作为恶意脚本报出来,提醒楼主注意。
      

  3.   

    不推荐使用修改注册表的方法:<HTML><HEAD>
    <script language="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 RegWsh = new ActiveXObject("WScript.Shell")
        hkey_key="header"    
        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
        hkey_key="footer"
        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
      }catch(e){}
    }
    //设置网页打印的页眉页脚为默认值
    function pagesetup_default()
    {
      try{
        var RegWsh = new ActiveXObject("WScript.Shell")
        hkey_key="header"    
        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")
        hkey_key="footer"
        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")
      }catch(e){}
    }
    </script>
    </HEAD><BODY><br/><br/><br/><br/><br/><br/><p align=center>
    <input type="button" value="清空页码" onclick=pagesetup_null()>
    <input type="button" value="恢复页码" onclick=pagesetup_default()><br>
    </p></BODY></HTML>
      

  4.   

    客户端和服务端都需要啊,
    在一个ERP项目里的,客户端是代理商,他们也需要打印自己的报表。
    我打算使用第三方的东西时,头儿不同意,即便用Adobe Acrobat也不行。