LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

JavaScript实现网页打印,可设置页眉、页脚、页边距

admin
2011年3月1日 17:50 本文热度 2932
WebBrowser是IE内置的浏览器控件,无需用户下载,即可实现客户端页面打印。

关于这个组件还有其他的用法,列举如下:  
  1. WebBrowser.ExecWB(1,1) 打开    
  2. Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口    
  3. Web.ExecWB(4,1) 保存网页    
  4. Web.ExecWB(6,1) 打印    
  5. Web.ExecWB(7,1) 打印预览    
  6. Web.ExecWB(8,1) 打印页面设置    
  7. Web.ExecWB(10,1) 查看页面属性    
  8. Web.ExecWB(15,1) 好像是撤销,有待确认    
  9. Web.ExecWB(17,1) 全选    
  10. Web.ExecWB(22,1) 刷新    
  11. Web.ExecWB(45,1) 关闭窗体无提示   
注意有可能执行时,会出现没有效果的错误,这时原因是可能你的浏览器限制了active对象的创建,只要取消限制就好了,取消方法如下:

打开你的ie浏览器internet选项—— 安全—— 自定义级别—— 把对没有标记为安全的activex控件进行初始化和脚本运行 设置为启用。  
  1. <SCRIPT language=javascript>   
  2. var HKEY_Root,HKEY_Path,HKEY_Key;    
  3. HKEY_Root="HKEY_CURRENT_USER";    
  4. HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";    
  5. var head,foot,top,bottom,left,right;   
  6.   
  7. //取得页面打印设置的原参数数据   
  8. function PageSetup_temp() {   
  9.     try    
  10.  {    
  11.   var Wsh=new ActiveXObject("WScript.Shell");    
  12.   HKEY_Key="header";    
  13. //取得页眉默认值   
  14.   head = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);    
  15.   HKEY_Key="footer";    
  16. //取得页脚默认值   
  17.   foot = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);    
  18.   HKEY_Key="margin_bottom";    
  19. //取得下页边距   
  20.   bottom = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);    
  21.   HKEY_Key="margin_left";    
  22. //取得左页边距   
  23.   left = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);    
  24.   HKEY_Key="margin_right";    
  25. //取得右页边距   
  26.   right = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);    
  27.   HKEY_Key="margin_top";    
  28. //取得上页边距   
  29.   top = Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key);    
  30.  }    
  31.  catch(e){   
  32.     alert("不允许ActiveX控件");   
  33.  }    
  34. }   
  35.   
  36. //设置网页打印的页眉页脚和页边距   
  37. function PageSetup_Null()    
  38. {    
  39.  try    
  40.  {    
  41.   var Wsh=new ActiveXObject("WScript.Shell");    
  42.   HKEY_Key="header";    
  43. //设置页眉(为空)   
  44.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");    
  45.   HKEY_Key="footer";    
  46. //设置页脚(为空)   
  47.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");    
  48.   HKEY_Key="margin_bottom";    
  49. //设置下页边距(0)   
  50.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");    
  51.   HKEY_Key="margin_left";    
  52. //设置左页边距(0)   
  53.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");    
  54.   HKEY_Key="margin_right";    
  55. //设置右页边距(0)   
  56.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0");    
  57.   HKEY_Key="margin_top";    
  58. //设置上页边距(8)   
  59.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"8");    
  60.  }    
  61.  catch(e){   
  62.     alert("不允许ActiveX控件");   
  63.  }    
  64. }    
  65. //设置网页打印的页眉页脚和页边距为默认值    
  66. function  PageSetup_Default()    
  67. {      
  68.  try    
  69.  {    
  70.   var Wsh=new ActiveXObject("WScript.Shell");    
  71.   HKEY_Key="header";    
  72.   HKEY_Key="header";    
  73. //还原页眉   
  74.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,head);    
  75.   HKEY_Key="footer";    
  76. //还原页脚   
  77.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,foot);    
  78.   HKEY_Key="margin_bottom";    
  79. //还原下页边距   
  80.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,bottom);    
  81.   HKEY_Key="margin_left";    
  82. //还原左页边距   
  83.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,left);    
  84.   HKEY_Key="margin_right";    
  85. //还原右页边距   
  86.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,right);    
  87.   HKEY_Key="margin_top";    
  88. //还原上页边距   
  89.   Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,top);    
  90.  }   
  91.  catch(e){   
  92.     alert("不允许ActiveX控件");   
  93.  }   
  94. }   
  95.   
  96. function printorder()   
  97. {   
  98.         PageSetup_temp();//取得默认值   
  99.         PageSetup_Null();//设置页面   
  100.         factory.execwb(6,6);//打印页面   
  101.         PageSetup_Default();//还原页面设置   
  102.         //factory.execwb(6,6);   
  103.         window.close();   
  104. }   
  105.   
  106. </script>   
  107. <OBJECT id=factory height=0 width=0 classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2></OBJECT> 

该文章在 2011/3/1 17:50:36 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved