10

我正在构建一个需要 WebBrowser 组件的软件。不幸的是,它不会正确显示我的页面。

我的内容使用这种 CSS 样式:

.content_mid{
background-image:url(http://img.awesome-o.net/Content_Mid.png);
background-size: 100% 100%;
vertical-align:text-top;
padding-left: 40px;
padding-right:20px;
min-height:400px; 
}

由于我已经发现 WebBrowser 组件使用了已安装的互联网浏览器版本,因此我在 Internet Explorer 上检查了 html,它显示完美。

在这里,您可以看到它在 IE 上显示的内容:

在此处输入图像描述

以下是它在 webbrowser 组件上的显示方式:

在此处输入图像描述

所以,我检查了浏览器版本:

Debug.WriteLine("WebBrowser version: " + webBrowser1.Version);
output: WebBrowser version: 9.0.8112.16443

所以我想应该没问题。

4

4 回答 4

23

本页描述了如何强制浏览器控件使用特定的渲染模式。

你也可以试试这个文档类型

<!DOCTYPE html>

和/或 head 元素中的这个 meta 元素:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
于 2012-04-19T22:40:22.483 回答
9

只是为了进一步参考需要这个的其他人:

首先:感谢BooLex Li 帮助我找到问题的答案。

您必须将某个注册表设置为正确的值:

32 位和 64 位应用程序有两组不同的密钥。

32位:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Value Key: yourapplication.exe

64位:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Value Key: yourapplication.exe

将此键设置为的值(此处取自 MSDN)为十进制值:

9999 (0x270F)
Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the  !DOCTYPE directive.

 9000 (0x2328)
 Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

8888 (0x22B8)
Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.

8000 (0x1F40)
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.

7000 (0x1B58)
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.

即使是强硬的 MSDN 也声称 9000 是自动分配的值。显然,这根本不是真的。

您可以在下面找到如何将这些密钥添加到注册表的代码。请注意,您的应用程序在调试时具有不同的进程名称。

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true);
        if (key != null)
        {
            key.SetValue("YourApplicationName.exe", 9000, RegistryValueKind.DWord);
        }

        key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true);
        if (key != null)
        {
            key.SetValue("YourApplicationName.exe", 9000, RegistryValueKind.DWord);
        }

所以谢谢大家,祝你好运

编辑:应该关闭用户帐户控制以使此代码正常工作。

于 2012-04-23T14:09:25.650 回答
3

我有同样的问题,我改变了这一行:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<meta http-equiv="X-UA-Compatible" content="IE=11" />

到最新的 IE 版本,它工作得很好。

于 2020-05-07T16:18:59.727 回答
0

您还可以向名为 X-UA-Compatible 的 IIS 应用程序添加响应标头,其值为 IE=Edge。我倾向于将它添加到我的 web.config

于 2013-12-02T14:32:36.163 回答