1. 程式人生 > >WebBrowser.ExecWB的完整例項,列印頁面、頁面設定、列印預覽、另存為、屬性等

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 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>