When you host an invisible WebBrowser control in your application, the NavigateComplete event does not fire after the first navigation. In addition, NavigateComplete does not navigate to another page when you use the navigate method. (This problem does not occur with Internet Explorer 5.01.)
↑ Back to the top
To resolve this problem, rather than make the WebBrowser control invisible, you can position the WebBrowser control so that it does not display its user interface on its container window. To do this, you can set the Left property of the WebBrowser control equal to the negative of the control's Width property. Alternatively, you can put the WebBrowser control behind other controls in your application.
↑ Back to the top
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
↑ Back to the top
Steps to Reproduce Behavior
- In Microsoft Visual Basic, create a new Standard EXE project.
- In the Toolbox, add a component reference to Microsoft Internet Control.
- Add a WebBrowser control, a text box, and three buttons to the default form, Form1.
- Copy the following code into the code module of Form1:
Option Explicit
Private Sub Command1_Click()
WebBrowser1.Navigate2 Text1.Text
End Sub
Private Sub Command2_Click()
WebBrowser1.Visible = Not WebBrowser1.Visible
End Sub
Private Sub Command3_Click()
MsgBox WebBrowser1.LocationURL
End Sub
Private Sub Form_Load()
WebBrowser1.Visible = False
Text1.Text = "http://www.microsoft.com"
Command1.Caption = "Navigate"
Command2.Caption = "Make Visible"
Command3.Caption = "Current_URL"
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
MsgBox "BeforeNavigate Event"
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
MsgBox "NavigateComplete Event"
End Sub
- Press the F5 key to run the project.
- Click Navigate. Both the BeforeNavigate event message box and the NavigateComplete event message box appear.
- In the text box, type another URL such as http://msdn.microsoft.com. The message box for the BeforeNavigate event appears, but the message box for the NavigateComplete event does not.
- Click Make Visible to show the WebBrowser control, or click Current_URL. The current page remains at http://www.microsoft.com.
↑ Back to the top
For more information on the NavigateComplete event, see the following MSDN Web Workshop page:
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
↑ Back to the top