document.body.style.margin = "20px 10px 50px 10px"; //top right bottom left

解决方案 »

  1.   

    <script language="JavaScript">
    <!--
    function SetMargin(iLeft, iTop, iRight, iBottom)
    {
    document.body.style.margin=iLeft+" "+iTop+" "+iRight+" "+iBottom;
    }
    //-->
    </script>
    <table width="100%" border="1">
    <tr>
    <td>
    left:<input name="left" type="text"><br>
    top:<input name="top" type="text"><br>
    right:<input name="right" type="text"><br>
    bottom:<input name="bottom" type="text"><br>
    <input type="button" value="test" onclick="javascript:SetMargin(left.value,top.value,right.value,bottom.value)">
    </td>
    </tr>
    </table>
      

  2.   

    打印的页边距, 用脚本在正规途径里是没有办法实现的. 当然用歪招, 比如说改注册表是可行的.
    还有一种方法就是使用网页打印控件.
    <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>
      

  3.   

    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup