Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


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.

↑ Back to the top


More information

To set the returnValue property to True, perform the following steps:
  1. Create a new Visual Basic standard EXE project. Form1 is created by default.
  2. Add a WebBrowser control to Form1.
  3. Add a Project Reference to the Microsoft HTML Object Library (Mshtml.tlb).
  4. 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
    					
  5. In the WebBrowser1_NavigateComplete event, add the following code:
    Private Sub WebBrowser1_NavigateComplete()
    
        Set objDoc = WebBrowser1.Document
        Set objWind = objDoc.parentWindow
        
    End Sub
  6. 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.

↑ Back to the top


References

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
261003 How to handle script errors as a WebBrowser control host
183616 How to trap JScript errors on a Web page
�For more information on�handling and avoiding web page errors�, see the following article on the Microsoft Developer Network (MSDN):� For more information regarding the onerror event, see the following MSDN Web site: For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB279535, kbwebbrowser, kbhowto

↑ Back to the top

Article Info
Article ID : 279535
Revision : 5
Created on : 7/13/2012
Published on : 7/13/2012
Exists online : False
Views : 128