HtmlWindow.Error Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when script running inside of the window encounters a run-time error.
public:
event System::Windows::Forms::HtmlElementErrorEventHandler ^ Error;
public event System.Windows.Forms.HtmlElementErrorEventHandler Error;
public event System.Windows.Forms.HtmlElementErrorEventHandler? Error;
member this.Error : System.Windows.Forms.HtmlElementErrorEventHandler
Public Custom Event Error As HtmlElementErrorEventHandler
Event Type
Examples
The following code example traps the error that results when a script on an HTML page attempts to access an object that is not defined in the document. The page must be fully loaded before the Error event handler is attached, otherwise the example will not work.
private void SuppressScriptErrors()
{
if (webBrowser1.Document != null)
{
webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(scriptWindow_Error);
}
}
private void scriptWindow_Error(object sender, HtmlElementErrorEventArgs e)
{
MessageBox.Show("Suppressed error!");
e.Handled = true;
}
Dim WithEvents ScriptWindow As HtmlWindow
Private Sub SuppressScriptErrors()
If (WebBrowser1.Document IsNot Nothing) Then
ScriptWindow = WebBrowser1.Document.Window
End If
End Sub
Private Sub ScriptWindow_Error(ByVal sender As Object, ByVal e As HtmlElementErrorEventArgs) Handles ScriptWindow.Error
MessageBox.Show("Suppressed error!")
e.Handled = True
End Sub
Remarks
HTML pages can contain script code, usually written in JScript or VBScript, that executes when a page is loaded. Error occurs whenever a script encounters a run-time error. Because script code is late-bound, which means that calls against the object are not resolved until run-time, errors can include everything from referencing a null object to calling an undefined property or method.
You can set the Handled property of HtmlElementErrorEventArgs to true
in order to prevent the native error dialog box in Internet Explorer from displaying.