Javascript:IE打印页面设置,预览,首页设置

复制代码
  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2 <html xmlns="http://www.w3.org/1999/xhtml">
  3 
  4 <head>
  5 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  6 <title>IE打印页面设置 </title>
  7 <style type="text/css" media="print">
  8 .noprint{
  9     display:none;
 10 }
 11 
 12 </style>
 13 <script language="javascript" type="text/javascript"> 
 14 function printsetup(){ 
 15 // 打印页面设置 
 16 wb.execwb(8,1); 
 17 } 
 18 function printpreview(){ 
 19 // 打印页面预览 
 20 
 21 wb.execwb(7,1); 
 22 
 23 } 
 24 
 25 function printit() 
 26 { 
 27 if (confirm('确定打印吗?')) { 
 28 wb.execwb(6,6) 
 29 } 
 30 } 
 31 
 32 //页面内要打印的内容加入中间<!--startprint1-->XXXXX<!--endprint1-->
 33 function preview(oper)
 34 {
 35 if (oper < 10){
 36 bdhtml=window.document.body.innerHTML;//获取当前页的html代码
 37 sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域
 38 eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
 39 prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
 40 
 41 prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
 42 window.document.body.innerHTML=prnhtml;
 43 window.print();
 44 window.document.body.innerHTML=bdhtml;
 45 
 46 
 47 } else {
 48 window.print();
 49 }
 50 
 51 }
 52 </script> 
 53 </head>
 54 
 55 <body>
 56 <div>
 57 geovindu
 58 creg
 59 g</div>
 60 <p>
 61 geovinduvb da</p>
 62 <div>
 63 2:组件法
 64 WebBrowser是IE内置的浏览器控件,无需用户下载.
 65 
 66 一、WebBrowser控件 
 67 <object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object> 
 68 二、WebBrowder控件的方法 
 69 //打印 
 70 
 71 WebBrowser1.ExecWB(6,1); 
 72 
 73 //打印设置 
 74 
 75 WebBrowser1.ExecWB(8,1); 
 76 
 77 //打印预览 
 78 
 79 WebBrowser1.ExecWB(7,1); 
 80 
 81 关于这个组件还有其他的用法,列举如下: 
 82 WebBrowser.ExecWB(1,1) 打开 
 83 Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口 
 84 Web.ExecWB(4,1) 保存网页 
 85 Web.ExecWB(6,1) 打印 
 86 Web.ExecWB(7,1) 打印预览 
 87 Web.ExecWB(8,1) 打印页面设置 
 88 Web.ExecWB(10,1) 查看页面属性 
 89 Web.ExecWB(15,1) 好像是撤销,有待确认 
 90 Web.ExecWB(17,1) 全选 
 91 Web.ExecWB(22,1) 刷新 
 92 Web.ExecWB(45,1) 关闭窗体无提示 
 93 </div>
 94 <object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" id="wb" name="wb" width="0"></object > 
 95 <input type="button" name="button_print" value="打印" class="noprint" onclick="javascript:printit()"/> 
 96 <input type="button" name="button_setup" value="打印页面设置" class="noprint" onclick="javascript:printsetup();"/> 
 97 <input type="button" name="button_show" value="打印预览" class="noprint" onclick="javascript:printpreview();"/>
 98 
 99 <script language="javascript">
100 function setHomepage()
101 {
102 if (document.all)
103 {
104 document.body.style.behavior='url(#default#homepage)';
105 document.body.setHomePage('http://www.w3school.com');
106 }
107 else if (window.sidebar)
108 {
109 if(window.netscape)
110 {
111 try
112 {
113 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
114 }
115 catch(e)
116 {
117 alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
118 }
119 }
120 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
121 prefs.setCharPref('browser.startup.homepage','http://www.w3school.com');
122 }
123 }
124 </script>
125 
126 <input type="button" class="noprint" value="设置首面" onclick="setHomepage();" /> 
127 </body>
128 
129 </html>
复制代码

 

posted @   ®Geovin Du Dream Park™  阅读(908)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
< 2013年3月 >
24 25 26 27 28 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6
点击右上角即可分享
微信分享提示