HOWTO: Cause Navigation to Occur in Same WebBrowser WindowID: Q185538
|
When hosting the Internet Explorer 4.x and higher WebBrowser control in a Visual Basic
application, you may want to have the navigation always occur in your
application and not other Internet Explorer windows. If you handle the
NewWindow2 event and set the Cancel flag equal to True, navigation is
canceled completely. Since NewWindow2 does not provide you with the URL to
navigate to as the Internet Explorer 3.x NewWindow event did, there doesn't
appear to be any way to have the navigation occur in the same window.
Fortunately, Internet Explorer 4.x and higher provide the WebBrowser_V1 object for
compatibility with Internet Explorer 3.x. Using the WebBrowser_V1 object,
you can have your application receive events from version 3.x, 4.x, and 5.x. That means that you can handle the version 3.x NewWindow event and
then have the navigation occur in the current window.
In order to implement this functionality in your Visual Basic application, follow these step:
Dim WithEvents Web_V1 as SHDocVwCtl.WebBrowser_V1
This will declare a WebBrowser_V1 variable that can receive events
WebBrowser_V1 provides you with the NewWindow event.
Set Web_V1 = WebBrowser1.Object
WebBrowser1.Navigate2 "http://www.microsoft.com/"
This sets the WebBrowser_V1 object to the existing Internet Explorer
WebBrowser object.
Private Sub Web_V1_NewWindow(ByVal URL As String, _
ByVal Flags As Long, _
ByVal TargetFrameName As String, _
PostData As Variant, _
ByVal Headers As String, _
Processed As Boolean)
Processed = True
WebBrowser1.Navigate URL
End SubFor additional information, please see the following article in the Microsoft Knowledge Base:
Q184876 HOWTO: Use the WebBrowser Control NewWindow2 EventFor more information, see the MSDN Online Web Workshop:
http://msdn.microsoft.com/workshop/(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation
Additional query words: NewWindow NewWindow2 kbWebBrowser kbDSupport kbdsi
Keywords : kbIE400 kbIE401 kbWebBrowser kbIE500
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 3, 1999