一个关于打印的例子

在开发的项目中用到了一些调用VBScript来实现win系统中打印的功能

注意:打开窗口必须为  openNewWin( url, 650, 650);

js 代码
  1. function openNewWin(url,winWid,winHig){   
  2.     var openParam = ""//打开窗口的参数   
  3.     w_top = screen.Height; //屏幕高度   
  4.     w_left = screen.Width;//屏幕宽度   
  5.   
  6.     //打开居中窗口的参数值   
  7.     openParam = "left=" + (w_left-winWid)/2 + ",top=" + (w_top-winHig)/2 + ",width="  
  8.     +winWid+",height="+winHig+",toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no,status=no";   
  9.   
  10.     window.open(url,'',openParam);   
  11. }  

 

下面是一个完整的例子

js 代码
  1. <script language=< span="">"javascript">   
  2. function printpr()   //预览函数   
  3. {   
  4. alert("如需打印表格和背景,请操作以下步骤:打开IE→工具→Internet选项→高级→中点击“还原默认设置”,之后在“打印”下的,“打  
  5.  
  6. 印背景颜色及图片”选项前打勾。");   
  7. document.all("qingkongyema").click();//打印之前去掉页眉,页脚   
  8. document.all("dayinDiv").style.display="none"//打印之前先隐藏不想打印输出的元素(此例中隐藏“打印”和“打印预览”两个按钮)   
  9. //document.all("closeid").style.display="none";   
  10. var OLECMDID = 7;   
  11. var PROMPT = 1;   
  12. var WebBrowser = '<object id=< span="">"WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">';   
  13. document.body.insertAdjacentHTML('beforeEnd', WebBrowser);   
  14. WebBrowser1.ExecWB(OLECMDID, PROMPT);   
  15. WebBrowser1.outerHTML = "";   
  16. document.all("dayinDiv").style.display="";//打印之后将该元素显示出来(显示出“打印”和“打印预览”两个按钮,方便别人下次打印   
  17.   
  18. )   
  19. document.all("closeid").style.display="";   
  20. }   
  21.   
  22. function printTure()   //打印函数   
  23. {   
  24.    alert("如需打印表格和背景,请操作以下步骤:打开IE→工具→Internet选项→高级→中点击“还原默认设置”,之后在“打印”下的,  
  25.  
  26. “打印背景颜色及图片”选项前打勾。");   
  27.     document.all('qingkongyema').click();//同上   
  28.     document.all("dayinDiv").style.display="none";//同上   
  29.     document.all("closeid").style.display="none";   
  30.     window.print();   
  31.     document.all("dayinDiv").style.display="";   
  32.     //document.all("closeid").style.display="";   
  33. }   
  34. function doPage()   
  35. {   
  36.     layLoading.style.display = "none";//同上   
  37. }   
  38.   
  39. </script>  
  40. <script language=< span="">"VBScript">   
  41. dim hkey_root,hkey_path,hkey_key   
  42. hkey_root="HKEY_CURRENT_USER"  
  43. hkey_path="\Software\Microsoft\Internet Explorer\PageSetup"  
  44. '//设置网页打印的页眉页脚为空   
  45. function pagesetup_null()   
  46. on error resume next   
  47. Set RegWsh = CreateObject("WScript.Shell")   
  48. hkey_key="\header"  
  49. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""  
  50. hkey_key="\footer"  
  51. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""  
  52. end function  
  53. '//设置网页打印的页眉页脚为默认值   
  54. function pagesetup_default()   
  55. on error resume next   
  56. Set RegWsh = CreateObject("WScript.Shell")   
  57. hkey_key="\header"  
  58. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"  
  59. hkey_key="\footer"  
  60. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d"  
  61. end function  
  62. </script>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值