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
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.
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 how to handle and avoid 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:
Additional query words: onerror
Keywords: kbhowto kbwebbrowser KB279535