转载地址:http://blog.sina.com.cn/s/blog_4c495b5f01011jgx.html
document.all.WebBrowser.ExecWB
WebBrowser控件实现对IE浏览器的各种控制
在不是js打开的页面上按window.close(),会有提示框,很烦,现在可以不用了,没有提示框直接关闭窗口。
试试下面代码:
<object id="WebBrowser" width=0 height=0classid="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下测试的,通过的。
代码:
--------------------------------------------------------------------------------
■打开■
<input name=ButtononClick=document.all.WebBrowser.ExecWB(1,1) type=buttonvalue=打开>
<OBJECTclassid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0id=WebBrowserwidth=0></OBJECT>
■另存为■
<input name=ButtononClick=document.all.WebBrowser.ExecWB(4,1) type=buttonvalue=另存为><OBJECTclassid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0id=WebBrowserwidth=0></OBJECT>
■属性■
<input name=ButtononClick=document.all.WebBrowser.ExecWB(10,1) type=buttonvalue=属性><OBJECTclassid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0id=WebBrowserwidth=0></OBJECT>
■打印■
<input name=ButtononClick=document.all.WebBrowser.ExecWB(6,1) type=buttonvalue=打印><OBJECTclassid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0id=WebBrowserwidth=0></OBJECT>
■页面设置■
<input name=ButtononClick=document.all.WebBrowser.ExecWB(8,1) type=buttonvalue=页面设置><OBJECTclassid=CLSID:8856F961_340A_11D0_A96B_00C04FD705A2 height=0id=WebBrowserwidth=0></OBJECT>
■刷新■
<input type=button value=刷新 name=refreshοnclick="window.location.reload()">
■导入收藏■
<input type="button" name="Button" value="导入收藏夹"onClick=window.external.ImportExportFavorites(true,);>
■导出收藏■
<input type="button" name="Button3" value="导出收藏夹"onClick=window.external.ImportExportFavorites(false,);>
■加入收藏■
<INPUT name=Button2οnclick="window.external.AddFavorite(location.href,document.title)" type=button value=加入收藏夹>
■整理收藏夹■
<INPUT name=Submit2οnclick="window.external.ShowBrowserUI(OrganizeFavorites, null)"type=button value=整理收藏夹>
■查看原文件■
<INPUT name=Button οnclick=window.location ="view-source:" + window.location.href type=buttonvalue=查看源文件>
■语言设置■
<INPUT name=Buttonοnclick="window.external.ShowBrowserUI(LanguageDialog, null)"type=button value=语言设置>
■前进■
<INPUT name=Submit οnclick=history.go(1) type=submitvalue=前进>
■后退■
<INPUT name=Submit2 οnclick=history.go(-1)type=submit value=后退>
<input name=Button.Click=document.all.WebBrowser.ExecWB(1,1) type=buttonvalue=打开>
<input name=Button.Click=document.all.WebBrowser.ExecWB(2,1) type=buttonvalue=关闭所有>
<input name=Button.Click=document.all.WebBrowser.ExecWB(4,1) type=buttonvalue=另存为>
<input name=Button.Click=document.all.WebBrowser.ExecWB(6,1) type=buttonvalue=打印>
<input name=Button.Click=document.all.WebBrowser.ExecWB(6,6) type=buttonvalue=直接打印>
<input name=Button.Click=document.all.WebBrowser.ExecWB(7,1) type=buttonvalue=打印预览>
<input name=Button.Click=document.all.WebBrowser.ExecWB(8,1) type=buttonvalue=页面设置>
<input name=Button.Click=document.all.WebBrowser.ExecWB(10,1) type=buttonvalue=属性>
<input name=Button.Click=document.all.WebBrowser.ExecWB(17,1) type=buttonvalue=全选>
<input name=Button.Click=document.all.WebBrowser.ExecWB(22,1) type=buttonvalue=刷新>
<input name=Button.Click=document.all.WebBrowser.ExecWB(45,1) type=buttonvalue=关闭>