使用你自己的浏览器打开新窗口
2004-09-14 16:41
274 查看
If you trap the NewWindow2 event for the WebBrowser control, you can stop all new windows opening, like this:
Code:
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
e.cancel = True
End Sub
Alternatively you could instantiate an InternetExplorer object and pass the handle to that, in this way you can trap what they do in InternetExplorer too.
Code:
Dim WithEvents ieChildBrowser As SHDocVw.InternetExplorer
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
ieChildBrowser = New SHDocVw.InternetExplorer()
ieChildBrowser.RegisterAsBrowser = True
e.ppDisp = ieChildBrowser
End Sub
Now you can trap the DownloadBegin event, cut out the URL they were going to, close the instance of IE, then Navigate2 in your own WebBrowser.
Code:
Private Sub ieChildBrowser_DownloadBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles ieChildBrowser.DownloadBegin
Dim strURL As String
strURL = ieChildBrowser.Document.URL
ieChildBrowser.Quit()
ieChildBrowser = Nothing
AxWebBrowser1.Navigate2(strURL)
End Sub
But I guess the first is simpler as it just stops them being able to do it at all.
Code:
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
e.cancel = True
End Sub
Alternatively you could instantiate an InternetExplorer object and pass the handle to that, in this way you can trap what they do in InternetExplorer too.
Code:
Dim WithEvents ieChildBrowser As SHDocVw.InternetExplorer
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
ieChildBrowser = New SHDocVw.InternetExplorer()
ieChildBrowser.RegisterAsBrowser = True
e.ppDisp = ieChildBrowser
End Sub
Now you can trap the DownloadBegin event, cut out the URL they were going to, close the instance of IE, then Navigate2 in your own WebBrowser.
Code:
Private Sub ieChildBrowser_DownloadBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles ieChildBrowser.DownloadBegin
Dim strURL As String
strURL = ieChildBrowser.Document.URL
ieChildBrowser.Quit()
ieChildBrowser = Nothing
AxWebBrowser1.Navigate2(strURL)
End Sub
But I guess the first is simpler as it just stops them being able to do it at all.
相关文章推荐
- 使用你自己的浏览器打开新窗口
- 如何使用默认浏览器在新窗口中打开 URL
- 通过使用浏览器对象模型,输出当前浏览器窗口中打开的文档的URL信息,并将显示在窗口中。
- 使用selenium+python;在页面A点击一个按钮跳转到页面B,页面A没有关闭,浏览器打开了一个B,切换窗口定位页面B的元素
- Java使用默认浏览器打开指定URL
- android 使用代码打开浏览器访问网页
- chm文件转换成html文件,解决chm文件无法使用浏览器打开的问题
- QT使用默认浏览器打开网页
- 使用 C 语言打开浏览器
- Unity3d调用system.windows.forms.dll使用OpenFileDialog打开文件选择窗口
- vSphere 5.5 使用Web Client打开控制台窗口显示连接超时
- 使用按钮控制以何种方式打开新窗口的属性介绍
- Java使用IE打开网页和使用默认浏览器打开网页的3种方法
- 使用C#打开新窗口关闭旧窗口的方法
- Webview展示网页,超链接使用默认浏览器打开
- JS使用cookie实现DIV提示层每次打开浏览器都能弹出
- 在浏览器中使用弹出窗口
- 使用 Python 实现:对着电脑吼一声,自动打开浏览器中的默认网站。
- 火狐,chrome等非IE浏览器使用window.open打开子窗口,父窗口意外关闭
- 子框架中使用javascript更改当前浏览器窗口的url