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>
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
原文地址:https://www.cnblogs.com/geovindu/p/2988184.html