How to have Delphi TWebbrowser component running in IE9 mode?

这一生的挚爱 提交于 2019-11-26 01:08:48

问题


I am experiencing Javascript errors with TWebbrowser due to the fact that TWebbrowser is running in IE7 compatibility mode.

Is there a way to prevent this and just have it run in IE9 mode?


回答1:


  1. Opt in to the browser emulation feature using the documented registry key.
  2. Depending on the browser emulation setting that you selected, you may need to ensure that your document contains a suitable DOCTYPE. Again, this is described in the documentation.

So, for example, if you wish to make the simplest possible change you would add the following registry setting:

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

The documentation for the value 9999 says:

9999 Windows Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.

Were you to use 9000 then you'd need also to modify the DOCTYPE of your document:

9000 Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.

The linked documentation also includes the information required to specify other IE versions.




回答2:


include in 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>



回答3:


Add this class to your code:

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;

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;

end;

Then add to your OnCreate of the Form:

TBrowserEmulationAdjuster.SetBrowserEmulationDWORD(TBrowserEmulationAdjuster.IE11_Quirks);

Thats all forever



来源:https://stackoverflow.com/questions/25843845/how-to-have-delphi-twebbrowser-component-running-in-ie9-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!