WebBrowser (If Page Fails To Load)??
I want to make it so if my webbrowser runs into a page that maybe doesn't exist and has a "This page cannot be displayed" then it will navigate to another.
I only know the code to make it navigate to another.
VB Code:
WebBrowser1.Navigate (URL)
Does anybody know the events I need to do this?
Thanks alot!
Re: WebBrowser (If Page Fails To Load)??
Look at this code.
VB Code:
' Add component for Microsoft Internet Controls
Option Explicit
Dim blnBusy As Boolean ' <----------------Add this declaration
Private Sub Command1_Click()
Dim i As Integer
'Navigate to the page
WebBrowser1.Navigate2 "http://www...coml" ' <-----Use your webpage
'Both the readystate and the busy properties of the WB control
'are not completely reliable. The best way to wait for loading to take
'place I have found so far is using a custom boolean variable that
'is set in the BeforeNavigate2 and NavigateComplete2 events.
blnBusy = True ' <---------------------Add these four lines
Do While blnBusy = True
DoEvents
Loop
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)
blnBusy = True
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
blnBusy = False
End Sub
Re: WebBrowser (If Page Fails To Load)??
Sorry, but I don't understand how this can tell me whether the page failed to load or not.
Re: WebBrowser (If Page Fails To Load)??
Check the NavigateError event. It will fire when problems occur when loading the site. Check the StatusCode to determine which error occurred; 404 is the one you're after here. The complete list of descriptions is here: http://msdn.microsoft.com/workshop/b...tuscodesvb.asp.
Re: WebBrowser (If Page Fails To Load)??
That error means your event declaration doesn't match the one of the control itself. In other words: the parameters in your declaration don't match with the ones set by the control. This probably happens because you're using a different Web Browser control version than the one that code uses. Don't directly paste from MSDN; use the NavigateError declaration that appears when you click the event in your IDE. That should handle it. :)
Re: WebBrowser (If Page Fails To Load)??
VB Code:
Private Sub WebBrowser2_NavigateError( _
ByVal pDisp As Object, _
ByVal URL As Variant, _
ByVal TargetFrameName As Variant, _
ByVal StatusCode As Variant, _
ByRef Cancel As Boolean)
If StatusCode = 404 Then MsgBox "I have failed you master"
End Sub
Procedure declaration does not match description of event.
Thanks for nothing Microsoft.
http://msdn.microsoft.com/workshop/b...igateerror.asp
Re: WebBrowser (If Page Fails To Load)??
VB Code:
Private Sub WebBrowser2_NavigateError(ByVal pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
MsgBox "I work"
End Sub
Works now, thanks everyone