0

Hello everyone,

I've been trying to generate a way to catch or suppress errors in my web browser control. actually what i really need in my browser is that if i run my project and the page cannot be display, to generate an error handler so instead of showing "The page cannot be display" to show something else, like "about:blank" for example or not display anything. i tried this:

Dim WithEvents objDoc As MSHTML.HTMLDocument
Dim WithEvents objWind As MSHTML.HTMLWindow2
Dim objEvent As CEventObj

Private Sub WebBrowser1_NavigateComplete()
Set objDoc = WebBrowser1.Document
Set objWind = objDoc.parentWindow
End Sub

Private Sub objWind_onerror(ByVal description As String, ByVal URL As String, ByVal line As Long)
Set objEvent = objWind.event
objEvent.returnValue = True
MsgBox (description)
End Sub

But i would like something diferent or better than this.
Any help will be appreciate.
Thanks in advance

3
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by C0ding
0

You should be able to check for the HTTP response code, either via an exposed property/function return of the WebBrowser control itself, or manually in the page headers. If the response code is an error (say 400, page not found) you could navigate "about:blank" or whatever else you want to do.

0

Thanks, but i don't like your suggestion... i'll find another way arround this.

0

You can try the following, just change the code to suit your needs -

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)

Set objDoc = WebBrowser1.document
Set objWind = objDoc.parentWindow
End Sub

Private Sub objWind_onerror(ByVal Description As String, ByVal URL As String, ByVal line As Long)

Set objEvent = objWind.event

objEvent.returnValue = True
End Sub

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)

Dim CtrlKey

If CtrlKey <> True Then
    Cancel = True
End If

Cancel = True
End Sub

Edited by AndreRet

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.