【问题标题】:WebBrowser component not showing CSS 3WebBrowser 组件未显示 CSS 3
【发布时间】:2012-05-01 11:37:16
【问题描述】:

我正在构建一个需要 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组件使用的是已安装的interwebs explorer版本,所以我在Internet Explorer上查看了html,它显示完美。

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

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

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

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

所以我猜应该没问题。

【问题讨论】:

  • 请不要在标题前加上“C#”之类的前缀。这就是标签的用途。

标签: c# css webbrowser-control


【解决方案1】:

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

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

到

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

到最新的IE版本,效果很好。

【讨论】:

    【解决方案2】:

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

    你也可以试试这个doctype:

    <!DOCTYPE html>
    

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

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

    【讨论】:

    • 感谢您的回答,只是我不明白的一件事。 “Internet Explorer 9 的默认值为 9000。” “描述:Internet Explorer 9。包含基于标准的 !DOCTYPE 指令的网页以 IE9 模式显示。”这对我来说似乎是正确的价值,还是你有不同的想法?
    • 您的页面是否定义了文档类型?
    • 是的:ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" rel="nofollow" target="_blank">w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> w3.org/1999/xhtml">跨度>
    • 对不起,我试过了,但它们似乎不起作用,谢谢你的回答。
    • 有一篇不错的博文包含更多详细信息,west-wind.com/weblog/posts/2011/May/21/…
    【解决方案3】:

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

    【讨论】:

    • 感谢您的回答,但恐怕这与 Windows 窗体应用程序有关。没有 web.config。
    【解决方案4】:

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

    首先: 感谢Boo & Lex 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);
            }
    

    谢谢大家,祝你好运

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

    【讨论】:

      猜你喜欢
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多