WPF WebBrowser suppress suppress pop-up script error dialog box but style changes need to be improved

Source: Internet
Author: User

1. Adding references

Using System.Reflection;
Using System.Windows.Controls;

2. Static class extension method (This)

public static Class Webbrowserextensions
{
public static void Suppressscripterrors (this WebBrowser webbrowser,bool hide)
{
FieldInfo finfo = typeof (WebBrowser). GetField ("_axiwebbrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
if (finfo==null)
{
Return
}

Object objbrowser = Finfo.getvalue (WebBrowser);
if (Objbrowser = = null)
{
Return
}
Objbrowser.gettype (). InvokeMember ("Silent", BindingFlags.SetProperty, NULL, Objbrowser, new object[] {hide});
}
}

3. Call,

Public MainWindow ()
{
InitializeComponent ();
Wb. Navigate ("http://www.alibaba.com/");
var browser = WB as WebBrowser;

Webbrowserextensions.suppressscripterrors (browser, true);
}

4. Summary.

Implementation does not pop-up script error box, but the style of the web itself has also changed, need to catch exceptions, processing.

WPF WebBrowser suppress suppress pop-up script error dialog box but style changes need to be improved

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.