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