javascript打印

问题:去除页眉页脚,设置打印的横纵向方式!
解决方案一:
修改注册表:
  var HKEY_Root,HKEY_Path,HKEY_Key;
  HKEY_Root = "HKEY_CURRENT_USER\\";
  HKEY_Path="Software\\Microsoft\\Internet Explorer\\PageSetup\\";
  
  function PageSetup_Null(){
   var Wsh = new ActiveXObject("WScript.Shell");
   HKEY_Key = "header";
   //Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);
   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
   HKEY_Key = "footer";
   //Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);
   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
  }
  
  window.onload=PageSetup_Null();
  
  function PageSetup_Reset(){
   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");
  }

  window.unonload=PageSetup_Reset();

由于注册表位置跟操作系统有关,不推荐使用。

解决方案二:
使用控件:
-------------http://www.7say.com/article.asp?id=112----------
利用ScriptX.cab控件进行WEB打印,可以控制"纵打"、 横打”和“页面的边距。打印代码如下:

<object id=factory viewastext style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
 codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=6,2,433,14">
</object>
<script defer>
function window.onload() {
 // -- advanced features
 factory.printing.SetMarginMeasure(2); // measure margins in inches
 factory.printing.printer = "HP DeskJet 870C";
 factory.printing.paperSize = "A4";
 factory.printing.paperSource = "Manual feed";
 factory.printing.collate = true;
 factory.printing.copies = 2;
 factory.printing.SetPageRange(false, 1, 3); // need pages from 1 to 3

 // -- basic features
 factory.printing.header = "This is MeadCo";
 factory.printing.footer = "Advanced Printing by ScriptX";
 factory.printing.portrait = false;
 factory.printing.leftMargin = 1.0;
 factory.printing.topMargin = 1.0;
 factory.printing.rightMargin = 1.0;
 factory.printing.bottomMargin = 1.0;
}

function Print(frame) {
 factory.printing.Print(true, frame) // print with prompt
</script>

<script language="javascript">
function printTure() //打印函数
{
 document.all("dayinDiv").style.display="none";//隐藏按钮
 factory.printing.Print(false); //调用控件打印
 document.all("dayinDiv").style.display="";//显示
}
</script>

<DIV align="center" id="dayinDiv" name="dayinDiv">
<input type=button value="打印本页" onclick="printTure()">
<input type=button value="页面设置" onclick="factory.printing.PageSetup()">
<input type=button value="打印预览" onclick="factory.printing.Preview()"><br>
</DIV>


关于ScriptX的下载和该控件的使用方法请登陆 http://www.meadroid.com/scriptx/index.asp 查看.
-----------------------------------------------
具体应用:
  <object id=factory style="display:none"
   classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
   codebase="<c:url value="/editor/ScriptX.cab#version=5,60,0,375"/>" viewastext>
  </object>

  <OBJECT id=WB classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT> 

  function printit()
  {
   factory.printing.header   =   "";  
         factory.printing.footer   =   "";  
   factory.printing.portrait = false;
     WB.ExecWB(6,6)
  }
  
  function setPrint()
  {
   factory.printing.header   =   "";  
         factory.printing.footer   =   "";  
   factory.printing.portrait = false;
   WB.ExecWB(8,1);
  }
  function previewPrint()
  {
   factory.printing.header   =   "";  
         factory.printing.footer   =   "";  
   factory.printing.portrait = false;
   WB.ExecWB(7,1)
  }

  function reset() {
   factory.printing.header   =   "&w&b页码,&p/&P";  
         factory.printing.footer   =   "&u&b&d";  
   factory.printing.portrait = true;
  }

  window.unonload=reset();

<DIV align="center" id="dayinDiv" name="dayinDiv">
<input type=button value="打印本页" onclick="printit()">
<input type=button value="页面设置" onclick="setPrint()">
<input type=button value="打印预览" onclick="previewPrint()"><br>
</DIV>

posted on 2006-11-14 12:26 扭转乾坤 阅读(1152) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2006年11月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

导航

统计

常用链接

留言簿(2)

随笔分类(31)

随笔档案(30)

文章分类(32)

文章档案(33)

相册

PHP小站-首页

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜