C # disable webbrowser control. The pop-up script error dialog box appears.

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.