Microsoft KB Archive/279535

= How to suppress run-time script errors as a WebBrowser control host in a Visual Basic application =

Article ID: 279535

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q279535



SUMMARY
To suppress the default Internet Explorer error message for the window onerror event, you can set the returnValue property of the event object to True.



MORE INFORMATION
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 </ol>

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.

<div class="references_section">