WebBrowser.ExecWB的完整实例,打印页面、页面设置、打印预览、另存为、属性等


<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input name=Button .Click=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<input name=Button .Click=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>
<input name=Button .Click=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>
<input name=Button .Click=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<input name=Button .Click=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>
<input name=Button .Click=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
<input name=Button .Click=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
<input name=Button .Click=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>
<input name=Button .Click=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>
<input name=Button .Click=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>
<input name=Button .Click=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>

WebBrowser组件的execWB方法
 
1. <object id=”WebBrowser” width=0 height=0 classid=”CLSID:8856F961-340A-11D0-A96B-00C04FD705A2”></object>
 
2. 调用方法:
WebBrowser.ExecWB nCmdID, nCmdExecOpt, [pvaIn], [pvaOut]
 
3. 参数说明:
(a).nCmdID
OLECMDID_OPEN = 1,
OLECMDID_NEW = 2,
OLECMDID_SAVE = 3,
OLECMDID_SAVEAS = 4,
OLECMDID_SAVECOPYAS = 5,
OLECMDID_PRINT = 6,
OLECMDID_PRINTPREVIEW = 7,
OLECMDID_PAGESETUP = 8,
OLECMDID_SPELL = 9,
OLECMDID_PROPERTIES = 10,
OLECMDID_CUT = 11,
OLECMDID_COPY = 12,
OLECMDID_PASTE = 13,
OLECMDID_PASTESPECIAL = 14,
OLECMDID_UNDO = 15,
OLECMDID_REDO = 16,
OLECMDID_selectALL = 17,
OLECMDID_CLEARselectION = 18,
OLECMDID_ZOOM = 19,
OLECMDID_GETZOOMRANGE = 20
OLECMDID_updateCOMMANDS = 21
OLECMDID_REFRESH = 22
OLECMDID_STOP = 23
OLECMDID_HIDETOOLBARS = 24
OLECMDID_SETPROGRESSMAX = 25
OLECMDID_SETPROGRESSPOS = 26
OLECMDID_SETPROGRESSTEXT = 27
OLECMDID_SETTITLE = 28
OLECMDID_SETDOWNLOADSTATE = 29
OLECMDID_STOPDOWNLOAD = 30
上面的关键词都可以在浏览器的菜单里面找到对应的选项﹐大家一看就明白的﹗
(b).nCmdExecOpt
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
LECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_SHOWHELP = 3
对于这个参数﹐一般来说﹐选1就可以了。
 
4.常用:
WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示
 
5.示例﹕
(a)调用IE的”另存为”功能的示例﹕
<object id=”WebBrowser” width=0 height=0 classid=”CLSID:8856F961-340A-11D0-A96B-00C04FD705A2”></object>
<A href=”.:WebBrowser.ExecWB(4,1);”>Save-存储</A>
 
(b)经过改写的登陆模式
<object id=”WebBrowser” width=0 height=0 classid=”CLSID:8856F961-340A-11D0-A96B-00C04FD705A2”></object>
<body οnlοad=”showModalDialog(‘Untitled-1.html’,0,’Status:NO;dialogWidth:418px;dialogHeight:288px’);document.all.WebBrowser.ExecWB(45,1);”>
 
 
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input name=Button .Click=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<input name=Button .Click=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>
<input name=Button .Click=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>
<input name=Button .Click=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<input name=Button .Click=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>
<input name=Button .Click=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
<input name=Button .Click=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
<input name=Button .Click=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>
<input name=Button .Click=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>
<input name=Button .Click=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>
<input name=Button .Click=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>
================================
完整演示实例:
<html>
<head>
<meta name=vs_targetSchema content=” http://schemas.microsoft.com/intellisense/ie5“>
<title>打印</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312”>
<!–media=print 这个属性可以在打印时有效–>
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: “宋体”;
font-size: 9pt;
}
</style>
</head>
<body >
<center class=”Noprint” >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<!–
在不是js打开的页面上按window.close(), 会有提示框,很烦,现在可以不用了,没有提示框直接关闭窗口。
试试下面代码:
<object id=”WebBrowser” width=0 height=0 classid=”CLSID:8856F961-340A-11D0-A96B-00C04FD705A2”>
</object>
<input type=”button” name=”Button” value=”关闭窗口” onClick=”document.all.WebBrowser.ExecWB(45,1)”>
试着改变参数会得到其他一些功能:
WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示
这些只对IE5.5以上版本有效,我是在IE6下测试的,通过的。
–>
<body>
<input type=button value=打开 οnclick=document.all.WebBrowser.ExecWB(1,1)>
<input type=button value=关闭现在所有的IE窗口并打开一个新窗口 οnclick=document.all.WebBrowser.ExecWB(3,1)>
<input type=button value=网页另存为 οnclick=document.all.WebBrowser.ExecWB(4,1)>
<input type=button value=查看页面属性 οnclick=document.all.WebBrowser.ExecWB(10,1)>
<input type=button value=全选 οnclick=document.all.WebBrowser.ExecWB(17,1)>
<input type=button value=刷新 οnclick=document.all.WebBrowser.ExecWB(22,1)>
<input type=button value=关闭窗体无提示 οnclick=document.all.WebBrowser.ExecWB(45,1)>
<input type=button value=打印 οnclick=document.all.WebBrowser.ExecWB(6,1) >
<input type=button value=直接打印 οnclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=打印预览 οnclick=document.all.WebBrowser.ExecWB(7,1)>
<input type=button value=页面设置 οnclick=document.all.WebBrowser.ExecWB(8,1)>
<br/>
</p>
<hr align=”center” width=”90%” size=”1” noshade>
</center>
<table width=”90%” border=”0” align=”center” cellpadding=”2” cellspacing=”0” class=”tabp”>
<tr>
<td colspan=”3” class=”tdp”>第1页</td>
</tr>
<tr>
<td width=”29%” class=”tdp”> </td>
<td width=”28%” class=”tdp”> </td>
<td width=”43%” class=”tdp”> </td>
</tr>
<tr>
<td colspan=”3” class=”tdp”> </td>
</tr>
<tr>
<td colspan=”3” class=”tdp”><table width=”100%” border=”0” cellspacing=”0” cellpadding=”0”>
<tr>
<td width=”50%” class=”tdp”><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<hr align=”center” width=”90%” size=”1” noshade class=”NOPRINT” >
<!–分页–>
<div class=”PageNext”></div>
<table width=”90%” border=”0” align=”center” cellpadding=”2” cellspacing=”0” class=”tabp”>
<tr>
<td class=”tdp”>第2页</td>
</tr>
<tr>
<td class=”tdp”>看到分页了吧</td>
</tr>
<tr>
<td class=”tdp”> </td>
</tr>
<tr>
<td class=”tdp”> </td>
</tr>
<tr>
<td class=”tdp”><table width=”100%” border=”0” cellspacing=”0” cellpadding=”0”>
<tr>
<td width=”50%” class=”tdp”><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
        </div>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先引入一个WebBrowser在需要打印页面,可以直接添加: 复制代码 代码如下: <object id="WebBrowser" classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0" width="0"> </object> 2 .页面设置打印预览 如下所示,直接调用即可 复制代码 代码如下: document.all.WebBrowser.ExecWB(6,6) 直接打印 document.all.WebBrowser.ExecWB(8,1) 页面设置 document.all.WebBrowser.ExecWB(7,1) 打印预览 3 隐藏不打印页面元素和分页 CSS 有个Media 属性,可以分开设置打印和显示的格式。 如 <style media="print" type="text/css"> …</style> 中间的格式将只在打印时起作用,不会影响显示界面。 所以可以设定 <style media="print" type="text/css"> .Noprint{display:none;} .PageNext{page-break-after: always;} </style> 然后给不想打印页面元素添加: class="Noprint" ,那就不会出现在打印打印预览中了。 想分页的地方添加: <div class="PageNext"></div> 就可以了。 4.打印页面的特定部分 通过将需要打印的特定部分另建一个页面,然后装入主页面的一个IFrame中,再调用IFrame的打印方法,只打印IFrame中的内容实现的。 如: <iframe visible" name="FrameId" width="100%" height="30%" src="NeedPrintedPage.asp"></iframe> 下面的pringFrame js函数将只打印Iframe中的内容,可以直接引用使用,如printFrame(FrameId); 复制代码 代码如下: window.print = printFrame; // main stuff function printFrame(frame, onfinish) { if ( !frame ) frame = window; function execOnFinish() { switch ( typeof(onfinish) ) { case "string": execScript(onfinish); break;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值