我的应用程序将一些 HTML 加载到 Web 浏览器中(来自 bsalsa.com 的 TEmbeddedWB),我想使用一些 CSS3 功能,例如 border-radius
。我安装了 Internet Explorer 9,因为它支持 border-radius
属性。好的,为了测试该属性在 Delphi 应用程序中是否有效,我创建了一个带有备忘录和 TEmbeddedWB 的新元素。在 Memo1OnChange
事件中,我让 Webbrowser 加载备忘录中的任何文本。然后我在备忘录中输入以下文本:
<div style="background-color:green; border-style: solid; border-width: 2px;
border-radius: 10px 10px 10px 10px; width:200px; height:200px;"></div>
Web 浏览器显示绿色框,但没有边框半径!然后我尝试将它保存到一个文件,并在 IE9 中加载它,并且边框半径清晰可见。
我还将注册表项 FEATURE_BROWSER_EMULATION
设置为我的 Project1.exe,值为 9999,Wow6432Node
中的注册表项也设置为 64 -位的东西。
我还根据 www.WhatsMyUserAgent.com 检查了用户代理, 它说我正在运行 MSIE9.0
我还需要做什么吗?
编辑 - 已修复: - 显然我的文档中需要以下元标记:
<meta http-equiv="X-UA-Compatible" content="IE=9" />
最佳答案
问题是我的 HTML 代码(参见 OP)不包括以下内容:
<meta http-equiv="X-UA-Compatible" content="IE=9" />
通过这样做,您可以避免必须修改注册表,因为上面强制 Web 浏览器以 IE9 标准模式呈现。 TWebbrowser 组件默认设置为 IE7。
我通过在修改和不修改注册表的情况下执行上述操作来测试它,并且自从我安装了 IE9 后它就起作用了。
当然,如果您自己创建文档,或者找到一些偷偷摸摸的方法将其注入(inject)到文档中,您只能确保存在上述代码。如果你想让 CSS3 的东西在第 3 方网站上工作,那么你需要注册表项(当然除非他们的文档中有上述代码)。
这是注册表项:HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/Main/FeatureControl/FEATURE_BROWSER_EMULATION
。添加一个 DWORD 键,并将其命名为 YOURAPPNAME.exe(在我的示例中为 Project1.exe)。将值设置为以下之一:
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)
因为我想强制使用 IE9 标准,所以我的 Regedit 窗口将如下所示:
通过这样做,您是在告诉应用程序中的网络浏览器您想要使用 IE9 标准(CSS3 和 HTML5 的东西)。 现在,我的 OP 中的代码将仍然不起作用,即使我们刚刚这样做了。为什么?因为我缺少一个 doctype
。通过添加文档类型,border radius 属性起作用了。
希望这对遇到同样问题的其他人有所帮助。
关于Delphi 网络浏览器和 CSS3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6724624/