由于TWebbrowser在IE7兼容模式下运行,我遇到了TWebbrowser的Javascript错误。
有没有办法防止这种情况,只是让它在IE9模式下运行?
答案 0 :(得分:11)
因此,例如,如果您希望进行最简单的更改,则需要添加以下注册表设置:
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版本所需的信息。
答案 1 :(得分:5)
包含在html中," HTTP的当量=" X UA兼容"含量=" IE =边缘"
" "
答案 2 :(得分:1)
将此类添加到您的代码中:
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;
然后将其添加到表单的OnCreate中:
TBrowserEmulationAdjuster.SetBrowserEmulationDWORD(TBrowserEmulationAdjuster.IE11_Quirks);
那就是永远