Using system.reflection;using system.windows;using system.windows.controls;using System.Windows.Navigation; namespace hc{//<summary>///MainWindow.xaml interactive logic///</summary> public partial class Mainwind Ow:window {public MainWindow () {InitializeComponent (); Webbrowsermain.navigating + = webbrowsermain_navigating; } void Webbrowsermain_navigating (object sender, NavigatingCancelEventArgs e) {Setwebbrowsersilen T (sender as WebBrowser, true); }///<summary>//Set browser silence, do not play error box///</summary>//<param name= "WebBrowser" > WebBrowser control Browser to set </param>//<param name= "Silent" > Silent </param> private void Setwebb Rowsersilent (WebBrowser WebBrowser, bool silent) {FieldInfo fi = typeof (WebBrowser). GetField ("_axiwebbrowser2", BindingFlags.Instance | BindingFlags.NonPublic); if (fi! = NULL) {Object Browser = fi. GetValue (WebBrowser); if (browser! = null) browser. GetType (). InvokeMember ("Silent", BindingFlags.SetProperty, NULL, browser, new object[] {Silent}); } } }}
WPF Settings WebBrowser control does not play script error prompt box