【问题标题】:Wpf WebBrowser suppressed script error but some scripts doesn't work properlyWpf WebBrowser 抑制脚本错误,但某些脚本无法正常工作
【发布时间】:2016-08-11 12:23:51
【问题描述】:

我已经通过以下代码在导航事件后禁用了 wpf webbrowser 控件中的 java 脚本错误。

公共静态无效 SetSilent(System.Windows.Controls.WebBrowser 浏览器,布尔静默) { 如果(浏览器 == 空) 抛出新的 ArgumentNullException("browser"); // get an IWebBrowser2 from the document IOleServiceProvider sp = browser.Document as IOleServiceProvider; if (sp != null) { Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046"); Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E"); object webBrowser; sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out webBrowser); if (webBrowser != null) { webBrowser.GetType().InvokeMember("Silent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.PutDispProperty, null, webBrowser, new object[] { silent }); } } } [ComImport, Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] private interface IOleServiceProvider { [PreserveSig] int QueryService([In] ref Guid guidService, [In] ref Guid riid, [MarshalAs(UnmanagedType.IDispatch)] out object ppvObject); }

但是一些java脚本不能正常工作并且没有得到任何错误没有影响。未来的模拟模式在注册表上也是正确的。

谢谢。

【问题讨论】:

    标签: wpf


    【解决方案1】:

    我找到了解决方案。导航完成后事件无法正常工作或状态未准备好。必须先检查。

    var 浏览器 = webBrowser1; if (browser == null || browser.Document == null) return; dynamic document = browser.Document; if (document.readyState != "complete") return; SetSilent(webBrowser1, true);

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 2010-11-20
      • 1970-01-01
      • 2022-11-13
      • 2016-04-11
      • 2014-12-07
      • 2015-04-04
      • 1970-01-01
      • 2017-04-08
      相关资源
      最近更新 更多