[英]Cannot force WebBrowser Control to render using current version of IE
I need the WebBrowser Control in my Windows Forms application to render pages using the latest version of Internet Explorer, or atleast the latest version that is installed on my machine - which is IE 11. 我需要Windows Forms应用程序中的WebBrowser控件,才能使用Internet Explorer的最新版本来呈现页面,或者至少安装在计算机上安装的最新版本(即IE 11)。
A few weeks ago, before I began working on this project I came across a website called DevDocs.io, and in IE 11 it works. 几周前,在我开始从事该项目之前,我遇到了一个名为DevDocs.io的网站,在IE 11中它可以正常工作。 However, even after applying the registry hack I cannot view DevDocs.io in the WebBrowser control because apparently I am using an "Unsupported" browser. 但是,即使在应用注册表黑客之后,我也无法在WebBrowser控件中查看DevDocs.io,因为显然我使用的是“不受支持”的浏览器。 It then goes on to say that I need to use either Firefox, Chrome or IE 10+. 然后继续说,我需要使用Firefox,Chrome或IE 10+。 I thought I was using IE 10+ since I had added the DWORD to the registry. 我以为我正在使用IE 10+,因为我已将DWORD添加到注册表中。
I've come across many websites that just don't display or behave normally due to the fact that the WebBrowser control still isn't rendering in IE11, or 10, or 9... 由于WebBrowser控件仍无法在IE11、10或9中呈现,因此我遇到了许多无法显示或正常运行的网站...
There are two things I would like to know: 我想知道两件事:
To be clear, I have gone to the Registry, and looked up: HKEY LOCAL MACHINE > SOFTWARE > MICROSOFT > INTERNET EXPLORER > MAIN > FEATURE CONTROL > FEATURE_BROWSER_EMULATION
and added a DWORD with values myApp.exe
and 11000
. 为了清楚起见,我进入了注册表,并进行了查找: HKEY LOCAL MACHINE > SOFTWARE > MICROSOFT > INTERNET EXPLORER > MAIN > FEATURE CONTROL > FEATURE_BROWSER_EMULATION
并添加了一个值为myApp.exe
和11000
的DWORD。
The 11000 is to get it to render using IE11, as per http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation . 根据http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation ,使用IE11可以渲染11000。
You need to add your registry key under both the main (64bit) node and the 32bit node, HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl
您需要在主(64位)节点和32位节点下添加注册表项,即HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl
You should then visit http://webdbg.com/ua.aspx to verify the document mode and UA string. 然后,您应该访问http://webdbg.com/ua.aspx以验证文档模式和UA字符串。
Here the method that I usually use and works for me (both for 32 bit and 64 bit applications): 这是我通常使用并为我工作的方法(适用于32位和64位应用程序):
[STAThread]
static void Main()
{
if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false))
{
//another application instance is running
return;
}
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe";
int ie_emulation = 10000;
try
{
string tmp = Properties.Settings.Default.ie_emulation;
ie_emulation = int.Parse(tmp);
}
catch { }
SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation);
m_webLoader = new FormMain();
Application.Run(m_webLoader);
}
finally
{
mutex.ReleaseMutex();
}
}
private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)
{
RegistryKey Regkey = null;
try
{
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
//If the path is not correct or
//If user't have priviledges to access registry
if (Regkey == null)
{
YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");
return;
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
//Check if key is already present
if (FindAppkey == "" + ieval)
{
YukLoggerObj.logInfoMsg("Application FEATURE_BROWSER_EMULATION already set to " + ieval);
Regkey.Close();
return;
}
//If key is not present or different from desired, add/modify the key , key value
Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);
//check for the key after adding
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == "" + ieval)
YukLoggerObj.logInfoMsg("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");
else
YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION setting failed; current value is " + ieval);
}
catch (Exception ex)
{
YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);
}
finally
{
//Close the Registry
if (Regkey != null)
Regkey.Close();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.