C# WebBrowser组件未显示CSS 3
我正在构建一个需要WebBrowser组件的软件。 不幸的是,它无法正确显示我的页面 我的内容使用此CSS样式:C# WebBrowser组件未显示CSS 3,c#,css,webbrowser-control,C#,Css,Webbrowser Control,我正在构建一个需要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; }
.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组件使用安装的interwebs explorer版本,所以我在InternetExplorer上检查了html,它显示得非常完美
在这里,您可以看到它在IE上显示的内容:
下面是它在webbrowser组件上的显示方式:
因此,我检查了浏览器版本:
Debug.WriteLine("WebBrowser version: " + webBrowser1.Version);
output: WebBrowser version: 9.0.8112.16443
我想这应该没问题。描述了如何强制浏览器控件使用特定的渲染模式
您也可以尝试此doctype:
和/或head元素中的此元元素:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
仅供其他需要此功能的人员参考: 首先: 多亏了, 谢谢你帮我找到问题的答案 您必须将某个注册表设置为正确的值: 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);
}
谢谢大家,祝你好运
编辑:应关闭用户帐户控制以使此代码正常工作。您还可以向IIS应用程序添加一个名为X-UA-Compatible的响应头,其值为IE=Edge。我倾向于将其添加到我的web.config中
我也有同样的问题,我更改了这一行:
到
到IE的最新版本,它运行得非常好。谢谢你的回答,只有一件事我不明白。“Internet Explorer 9的默认值为9000。”“说明:Internet Explorer 9。包含基于标准的!DOCTYPE指令的网页以IE9模式显示。”这似乎对我来说是正确的值,还是您有不同的想法?您的页面是否定义了DOCTYPE?是的:抱歉,我尝试了它们vyt,但它们似乎不起作用,谢谢你的回答。有一篇很好的博文包含了更多的细节,请不要在标题前加上“C”之类的字头。这就是标签的作用。谢谢你的回答,但恐怕这与windows窗体应用程序有关。没有web.config。
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);
}