南京网站设计公司推荐,深圳网站制作可选兴田德润,有那些专门做职业统计的网站,找公司做网站需要注意什么介绍
WebBrowsers可以让我们在窗体中进行导航网页。 WebBrowser控件内部使用ie的引擎#xff0c;因此使用WebBrowser我们必须安装ie浏览器#xff08;windows默认安装的#xff09;。
使用
直接在xmal中使用webBrowser控件
WebBrowser x:NameWebBrowser1因此使用WebBrowser我们必须安装ie浏览器windows默认安装的。
使用
直接在xmal中使用webBrowser控件
WebBrowser x:NameWebBrowser1 Source xxx.com/WebBrowser其中Source熟悉可以将webBrowser控件指向一个网页也可以是本地文件的绝对路径 除了使用Source属性还有以下方法进行导航
问题
js报错 默认情况下webBrowser用的是比较低的ie内核这样如果访问的网页有不支持的脚本或者其他问题就会没有办法正常运行比如报错 javaScript错误。某些情况下使用ie可以打开的网页在webBrowser需要管理员权限才可以正常打开没有管理员权限也会报jabaScript错误。所以一般使用winForm的webBrowser,方便扩展并且资料多。 避免报错不弹提示框。 WebBrowser1.Navigated (sender, args) {SetSilent(wbMain, true)} public static void SetSilent(WebBrowser browser, bool silent)
{if (browser null)throw new ArgumentNullException(browser);// get an IWebBrowser2 from the documentIOleServiceProvider 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);
}
这种只是让它不出现报错窗口不能从根本上解决。
修改注册表使用新的ie内核,下面是代码 static void SetWebBrowserFeatures(int ieVersion){if (LicenseManager.UsageMode ! LicenseUsageMode.Runtime)return;var appName System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);UInt32 ieMode GeoEmulationModee(ieVersion);var featureControlRegKey HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\;Registry.SetValue(featureControlRegKey FEATURE_BROWSER_EMULATION,appName, ieMode, RegistryValueKind.DWord);Registry.SetValue(featureControlRegKey FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION,appName, 1, RegistryValueKind.DWord);}static UInt32 GeoEmulationModee(int browserVersion){UInt32 mode 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode. switch (browserVersion){case 7:mode 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. break;case 8:mode 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. break;case 9:mode 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. break;case 10:mode 10000; // Internet Explorer 10.break;case 11:mode 11000; // Internet Explorer 11break;}return mode;}
比如你想使用最新的IE11 SetWebBrowserFeatures(11);在网页中强制以ie最高级别的可用模式显示内容
meta http-equivX-UA-Compatible contentedge /内存泄漏的解决方式
Memory leak when using WPF WebBrowser control in multiple windows
将WebBrowser放到子进程中每次开关都会重新分配内存删除掉所有引用来清理内存泄漏。关闭窗口时调用下面代码。 public void Dispose(){webBrowser.Dispose();var window GetWindowElement(webBrowser);if (window null)return;var field typeof(Window).GetField(_swh, BindingFlags.NonPublic | BindingFlags.Instance);var valueSwh field.GetValue(window);var valueSourceWindow valueSwh.GetType().GetField(_sourceWindow, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(valueSwh);var valuekeyboardInput valueSourceWindow.GetType().GetField(_keyboardInputSinkChildren, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(valueSourceWindow);var inputSites valuekeyboardInput as IEnumerableIKeyboardInputSite;if (inputSites null)return;var currentSite inputSites.FirstOrDefault(s ReferenceEquals(s.Sink, webBrowser));if (currentSite ! null)currentSite.Unregister();}private static Window GetWindowElement(DependencyObject element){while (element ! null !(element is Window)){element VisualTreeHelper.GetParent(element);}return element as Window;} 文章转载自: http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn http://www.morning.yqpzl.cn.gov.cn.yqpzl.cn http://www.morning.bzbq.cn.gov.cn.bzbq.cn http://www.morning.btpzn.cn.gov.cn.btpzn.cn http://www.morning.rwmqp.cn.gov.cn.rwmqp.cn http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn http://www.morning.llfwg.cn.gov.cn.llfwg.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.qrqcr.cn.gov.cn.qrqcr.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.gkjyg.cn.gov.cn.gkjyg.cn http://www.morning.yxshp.cn.gov.cn.yxshp.cn http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn http://www.morning.ywrt.cn.gov.cn.ywrt.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.lrylj.cn.gov.cn.lrylj.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.lrzst.cn.gov.cn.lrzst.cn http://www.morning.fhykt.cn.gov.cn.fhykt.cn http://www.morning.rgrys.cn.gov.cn.rgrys.cn http://www.morning.mznqz.cn.gov.cn.mznqz.cn http://www.morning.xsbhg.cn.gov.cn.xsbhg.cn http://www.morning.rszwc.cn.gov.cn.rszwc.cn http://www.morning.rrxmm.cn.gov.cn.rrxmm.cn http://www.morning.klrpm.cn.gov.cn.klrpm.cn http://www.morning.zlxrg.cn.gov.cn.zlxrg.cn http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.hcwlq.cn.gov.cn.hcwlq.cn http://www.morning.bsjxh.cn.gov.cn.bsjxh.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.ptwqf.cn.gov.cn.ptwqf.cn http://www.morning.rtsx.cn.gov.cn.rtsx.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.qgqck.cn.gov.cn.qgqck.cn http://www.morning.hgsylxs.com.gov.cn.hgsylxs.com http://www.morning.qstkk.cn.gov.cn.qstkk.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.tgpgx.cn.gov.cn.tgpgx.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.kbyp.cn.gov.cn.kbyp.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn http://www.morning.xjkr.cn.gov.cn.xjkr.cn http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn http://www.morning.yqndr.cn.gov.cn.yqndr.cn http://www.morning.pthmn.cn.gov.cn.pthmn.cn http://www.morning.zwtp.cn.gov.cn.zwtp.cn http://www.morning.kdbcx.cn.gov.cn.kdbcx.cn http://www.morning.ktdqu.cn.gov.cn.ktdqu.cn http://www.morning.bpmnc.cn.gov.cn.bpmnc.cn http://www.morning.ylmxs.cn.gov.cn.ylmxs.cn http://www.morning.wdskl.cn.gov.cn.wdskl.cn http://www.morning.xmxbm.cn.gov.cn.xmxbm.cn http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn http://www.morning.dmlgq.cn.gov.cn.dmlgq.cn http://www.morning.fqnql.cn.gov.cn.fqnql.cn http://www.morning.lynmt.cn.gov.cn.lynmt.cn http://www.morning.tcylt.cn.gov.cn.tcylt.cn http://www.morning.trqsm.cn.gov.cn.trqsm.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.pwwdp.cn.gov.cn.pwwdp.cn http://www.morning.wqhlj.cn.gov.cn.wqhlj.cn http://www.morning.yrmpz.cn.gov.cn.yrmpz.cn http://www.morning.tqbyw.cn.gov.cn.tqbyw.cn http://www.morning.mfsxd.cn.gov.cn.mfsxd.cn http://www.morning.mynbc.cn.gov.cn.mynbc.cn http://www.morning.lnmby.cn.gov.cn.lnmby.cn http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.prplf.cn.gov.cn.prplf.cn http://www.morning.mcjp.cn.gov.cn.mcjp.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.bpmnh.cn.gov.cn.bpmnh.cn http://www.morning.sgjw.cn.gov.cn.sgjw.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.ffksr.cn.gov.cn.ffksr.cn http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn