This is not a new issue. I have posted a lot about this issue on the internet, and I will make a summary today.
When we use the WebBrowser control, an error message box is displayed, which will suspend some automatically executed programs. How can we disable it?
Set the WebBrowser control ScriptErrorsSuppressed to True. The script error dialog box cannot be displayed. The ScriptErrorsSuppressed attribute encapsulates the Silent attribute of the basic COM control, therefore, setting the ScriptErrorsSuppressed attribute is the same as setting the Slient attribute of its basic COM control. windows. the Forms assembly can be confirmed.
To solve this problem, some people specifically derive a new class from WebBrowser and rewrite the AttachInterfaces method. In fact, it is not necessary. The effect is the same as setting the ScriptErrorsSuppressed attribute directly.
Note that:
Setting ScriptErrorsSuppressed to True disables all dialogs, such as prompting Activex download, execution, and secure logon.
If you do not want to disable a dialog box other than a script error, use the sample code on MSDN:
Private void browser_DocumentCompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
{
(WebBrowser) sender). Document. Window. Error + = new HtmlElementErrorEventHandler (Window_Error );
}
Private void Window_Error (object sender, HtmlElementErrorEventArgs e)
{
// Ignore the error and suppress the error dialog box.
E. Handled = true;
}