如何在IE9模式下运行Delphi TWebbrowser组件?

use*_*894 13 delphi twebbrowser

由于TWebbrowser在IE7兼容模式下运行,我遇到了TWebbrowser的Javascript错误.

有没有办法防止这种情况,只是让它在IE9模式下运行?

Dav*_*nan 11

  1. 使用记录的注册表项选择使用浏览器仿真功能.
  2. 根据您选择的浏览器仿真设置,您可能需要确保文档包含合适的DOCTYPE.同样,这在文档中描述.

因此,例如,如果您希望进行最简单的更改,则需要添加以下注册表设置:

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
   SOFTWARE
      Microsoft
         Internet Explorer
            Main
               FeatureControl
                  FEATURE_BROWSER_EMULATION
                     YourExeNameGoesHere.exe = (DWORD) 00009999

该值的文档9999说:

9999 Windows Internet Explorer 9.网页以IE9标准模式显示,与!DOCTYPE指令无关.

如果您要使用,9000那么您还需要修改文档的DOCTYPE:

9000 Internet Explorer 9.包含基于标准的网页!DOCTYPE指令以IE9模式显示.Internet Explorer 9的默认值.

链接的文档还包括指定其他IE版本所需的信息.

  • TY.此解决方案有效.对于64位操作系统上的32位应用程序,您需要在...下面添加条目:SOFTWARE\Wow6432Node\Microsoft\... (2认同)
  • 这是正确的。除非您使用没有单独的 32 位和 64 位视图的“HKCU\Software”。当然,如果您在安装程序中添加设置,那么注册表重定向器将为您完成工作并重定向到 32 位视图。假设您的 32 位程序使用 32 位安装程序。 (2认同)

小智 5

包含在html中,"http-equiv ="X-UA-Compatible"content ="IE = edge"

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body> 
                your code ....
</body>
</html>
Run Code Online (Sandbox Code Playgroud)


Ing*_*ngo 5

将此类添加到您的代码中:

type TBrowserEmulationAdjuster = class
  private
      class function GetExeName(): String; inline;
   public const
      // Quelle: https://msdn.microsoft.com/library/ee330730.aspx, Stand: 2017-04-26
      IE11_default   = 11000;
      IE11_Quirks    = 11001;
      IE10_force     = 10001;
      IE10_default   = 10000;
      IE9_Quirks     = 9999;
      IE9_default    = 9000;
      /// <summary>
      /// Webpages containing standards-based !DOCTYPE directives are displayed in IE7
      /// Standards mode. Default value for applications hosting the WebBrowser Control.
      /// </summary>
      IE7_embedded   = 7000;
   public
      class procedure SetBrowserEmulationDWORD(const value: DWORD);
end platform;
Run Code Online (Sandbox Code Playgroud)
class function TBrowserEmulationAdjuster.GetExeName(): String;
begin
    Result := TPath.GetFileName( ParamStr(0) );
end;

class procedure TBrowserEmulationAdjuster.SetBrowserEmulationDWORD(const value: DWORD);
const registryPath = 'Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION';
var
    registry:   TRegistry;
    exeName:   String;
begin
    exeName := GetExeName();

    registry := TRegistry.Create(KEY_SET_VALUE);
    try
       registry.RootKey := HKEY_CURRENT_USER;
       Win32Check( registry.OpenKey(registryPath, True) );
       registry.WriteInteger(exeName, value)
    finally
       registry.Destroy();
    end;
Run Code Online (Sandbox Code Playgroud)

结尾;

然后添加到表单的 OnCreate 中:

TBrowserEmulationAdjuster.SetBrowserEmulationDWORD(TBrowserEmulationAdjuster.IE11_Quirks);
Run Code Online (Sandbox Code Playgroud)

那是永远