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 onload="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=打开 onclick=document.all.WebBrowser.ExecWB(1,1)> <input type=button value=关闭现在所有的IE窗口并打开一个新窗口 onclick=document.all.WebBrowser.ExecWB(3,1)> <input type=button value=网页另存为 onclick=document.all.WebBrowser.ExecWB(4,1)> <input type=button value=查看页面属性 onclick=document.all.WebBrowser.ExecWB(10,1)> <input type=button value=全选 onclick=document.all.WebBrowser.ExecWB(17,1)> <input type=button value=刷新 onclick=document.all.WebBrowser.ExecWB(22,1)> <input type=button value=关闭窗体无提示 onclick=document.all.WebBrowser.ExecWB(45,1)> <input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1) > <input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)> <input type=button value=页面设置 onclick=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> |