To set the
returnValue property to True, perform the following steps:
- Create a new Visual Basic standard EXE project. Form1 is
created by default.
- Add a WebBrowser control to Form1.
- Add a Project Reference to the Microsoft HTML Object
Library (Mshtml.tlb).
- In the declarations section of Form1, add the following
code:
Dim WithEvents objDoc As MSHTML.HTMLDocument
Dim WithEvents objWind As MSHTML.HTMLWindow2
Dim objEvent As CEventObj
- In the WebBrowser1_NavigateComplete event, add the following code:
Private Sub WebBrowser1_NavigateComplete()
Set objDoc = WebBrowser1.Document
Set objWind = objDoc.parentWindow
End Sub
- Add an event handler for the window onerror event as follows:
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
Note This method will not trap compilation errors. In addition, this
method only suppresses the error message when you turn off the Scripting
Debugger in Internet Explorer. By design, if the Scripting Debugger is turned
on, the error is not suppressed. To turn off the Scripting Debugger in Internet
Explorer, on the
Tools menu, click
Internet Options. On the
Advanced tab, select the
Disable script debugging check box, and then click
OK.