http://blog.csdn.net/net_lover/archive/2004/07/06/35228.aspx原来答案在这里,如果谁还有其他的方法,给多人,不然大家进来都有分。

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT=""><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,"&p/&P") ;
      }
     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){}
    }// 打印
    function PrintPage()
    {
     PageSetup_Null() ;
     window.print() ;
     PageSetup_Default() ;
    }</Script></HEAD><BODY>
    javascript的test page print<br>
    xxxxxxxxxxx<br>
    yyyyyyyyyyyyyy<br>
    kkkkkkkkkkkk<br>
    <a href="#" onClick="PrintPage();">Print Page</a>
    <object   id="WebBrowser"   width=0   height=0   classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
    <input   type="button"   onClick="document.all.WebBrowser.ExecWB(7,1)"   value="打印预览"></BODY>
    </HTML>