WebBrowser控件 – 未应用CSS

我需要在Framework 4.5中的Browser控件中托管一个在线支付网关,并且遇到了CSS未正确应用或根本没有应用的问题。

我已经通过所有选项没有运气,并尝试使用此处详述的Navigate覆盖,并在下面显示页面正确呈现但在新浏览器窗口中弹出。

 browser.Navigate(url, ""); 

我要做的是使一些webservice调用依赖于用户点击的控件,所以我已经点击了MouseDown事件。

我也试过一个WPF应用程序,没有运气,看看Browser控件是否不同。

我正在等待看看支付网关的人是否可以为我提供CSS,所以我可以手动应用它,但在此期间有没有人有任何其他建议?

****更新****

尝试了下面的建议没有运气。

我也试过这个Internet Explorer本地计算机区域锁定 ,看它是否有任何差异,但它没有。

*****进一步更新*****我在这个网站上收到以下关于证书的错误:

证书错误

还有一个JavaScript错误,告诉我不支持AddEvent 。 我想知道这是否是失败的浏览器仿真?

另一个更新

在上述情况下,我遵循了Noseratio的出色建议并添加了以下内容:

 SetBrowserFeatureControlKey("FEATURE_WARN_ON_SEC_CERT_REV_FAILED", fileName, 0); 

托管WebBrowser控件的应用程序不支持此function。

通常,实现FEATURE_BROWSER_EMULATION解决这样的问题,但是你提到你已经这样做了。 如果您想使用自己的HTML + CSS尝试,我可以共享一个测试应用程序。

 using Microsoft.Win32; using System; using System.Diagnostics; using System.Threading.Tasks; using System.Windows.Forms; namespace WbTest { public partial class Form1 : Form { public Form1() { SetBrowserFeatureControl(); InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { DoNavigationAsync().ContinueWith(_ => { MessageBox.Show("Navigation complete!"); }, TaskScheduler.FromCurrentSynchronizationContext()); } private async Task DoNavigationAsync() { TaskCompletionSource documentCompleteTcs = null; WebBrowserDocumentCompletedEventHandler handler = delegate { if (documentCompleteTcs.Task.IsCompleted) return; documentCompleteTcs.SetResult(true); }; documentCompleteTcs = new TaskCompletionSource(); this.wb.DocumentCompleted += handler; // could do this.wb.Navigate(url) here this.wb.DocumentText = ""+ ""; await documentCompleteTcs.Task; this.wb.DocumentCompleted -= handler; dynamic document = this.wb.Document.DomDocument; dynamic navigator = document.parentWindow.navigator; var info = "\n navigator.userAgent: " + navigator.userAgent + "\n navigator.appName: " + navigator.appName + "\n document.documentMode: " + document.documentMode + "\n document.compatMode: " + document.compatMode; MessageBox.Show(info); } private static void SetBrowserFeatureControl() { // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx // WebBrowser Feature Control settings are per-process var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName); // make the control is not running inside Visual Studio Designer if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0) return; SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode()); } private static void SetBrowserFeatureControlKey(string feature, string appName, uint value) { using (var key = Registry.CurrentUser.CreateSubKey( String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature), RegistryKeyPermissionCheck.ReadWriteSubTree)) { key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord); } } private static UInt32 GetBrowserEmulationMode() { int browserVersion = 7; using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues)) { var version = ieKey.GetValue("svcVersion"); if (null == version) { version = ieKey.GetValue("Version"); if (null == version) throw new ApplicationException("Microsoft Internet Explorer is required!"); } int.TryParse(version.ToString().Split('.')[0], out browserVersion); } // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10. UInt32 mode = 10000; switch (browserVersion) { case 7: // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control. mode = 7000; break; case 8: // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8 mode = 8000; break; case 9: // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9. mode = 9000; break; default: // use IE10 mode by default break; } return mode; } } } 

首先,按原样试试,你应该看到这样的东西:

在此处输入图像描述

注意documentModecompatMode值,这些值对应于HTML5标准模式。 然后尝试使用HTML,看看它们是否保持不变。