<script language="JavaScript" type="text/javascript">
  function printsetup()
    { 
  // 打印页面设置 
  wb.execwb(8,1); 
  } 
  
  function printpreview()
      { 
  // 打印页面预览 
  wb.execwb(7,1); 
  }   function printit() 
  { 
      if (confirm('确定打印吗?')) 
        { 
          wb.execwb(6,6); 
      } 
  } 
</script>    <object id="wb" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
        name="wb">
    </object>
调用printpreview()后,打印页面预览时,页眉页脚每次都是自己手动设置,很烦,有没有什么好的方法,可以直接在JavaScript中设置.请高手指点........需要调用WScript.Shell组件的就不用说了,我怎么知道,这种方法有点缺陷,一般的服务器都禁止使用这个组件.
另外,<object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://www.gyit.com/ActiveX/ScriptX.cab#Version=5,60,0,360"></object>,
这种方法,需要加载ActiveX控件,如果电脑没有连接外网,也就没有办法使用了.除了这些还有其他方法吗?????

解决方案 »

  1.   

    <script language="JavaScript">
    var hkey_root,hkey_path,hkey_key
    hkey_root="HKEY_CURRENT_USER"
    hkey_path="SoftwareMicrosoftInternet ExplorerPageSetup"
    //设置网页打印的页眉页脚为空
    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>
    <input type="button" value="清空页码" onclick=pagesetup_null()>
    <input type="button" value="恢复页码" onclick=pagesetup_default()>
      

  2.   

    还是要用WScript.Shell这个组件,不安全啊......