如何通过JS控制IE的打印参数,如页边距等,直接在程序里指定

解决方案 »

  1.   

    网上搜来的<object id="factory" style="display:none" viewastext
      classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
      codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"
    ></object>
    <input type=button value=页面设置 onclick="factory.printing.PageSetup()">
    <input type=button value=打印预览 onclick="factory.printing.Preview()">
     
    <script language=javascript>
    function window.onload()
    {
       // -- advanced features
       factory.printing.SetMarginMeasure(2) // measure margins in inches
       factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
       factory.printing.printer = "HP DeskJet 870C"
       factory.printing.copies = 2
       factory.printing.collate = true
       factory.printing.paperSize = "A4"
       factory.printing.paperSource = "Manual feed"
       // -- basic features
       factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页"
       factory.printing.footer = "(自定义页脚)"
       factory.printing.portrait = false
       factory.printing.leftMargin = 0.75
       factory.printing.topMargin = 1.5
       factory.printing.rightMargin = 0.75
       factory.printing.bottomMargin = 1.5
    }
    function Print(frame) {
      factory.printing.Print(true, frame) // print with prompt
    }
    </script>
    <input type=button value="打印本页" onclick="factory.printing.Print(false)">
    <input type=button value="页面设置" onclick="factory.printing.PageSetup()">
    <input type=button value="打印预览" onclick="factory.printing.Preview()"><br>
    <a href="http://www.meadroid.com/scriptx/docs/printdoc.htm?static"  target=_blank>具体使用手册,更多信息,点这里</a>
     
      

  2.   

    //去掉打印时的页眉页脚
    <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 Wsh=new ActiveXObject("WScript.Shell");
      HKEY_Key="header";
      Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
      HKEY_Key="footer";
      Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
     }
     catch(e){}
    }
    //设置网页打印的页眉页脚为默认值
    function  PageSetup_Default()
    {  
     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){}
    }
    </script>
    <input type="button" value="清空页码" onclick=PageSetup_Null()>
    <input type="button" value="恢复页码" onclick=PageSetup_Default()>
      

  3.   

    现在关键是ScriptX.cab这个控件找不到,总是报factory.printing为空