【问题标题】:Cannot force WebBrowser Control to render using current version of IE无法强制 WebBrowser 控件使用当前版本的 IE 呈现
【发布时间】:2014-06-14 21:23:17
【问题描述】:

我需要在我的 Windows 窗体应用程序中使用 WebBrowser 控件,以使用 最新 版本的 Internet Explorer 或至少安装在我的机器上的最新版本 - IE 11 呈现页面。 p>

几周前,在我开始从事这个项目之前,我遇到了一个名为 DevDocs.io 的网站,它在 IE 11 中运行。但是,即使在应用注册表黑客之后,我也无法在 WebBrowser 控件中查看 DevDocs.io,因为显然我使用的是“不受支持”的浏览器。然后它继续说我需要使用 Firefox、Chrome 或 IE 10+。我以为我使用的是 IE 10+,因为我已将 DWORD 添加到注册表中。

我遇到了 许多 网站,这些网站由于 WebBrowser 控件仍未在 IE11、10 或 9 中呈现这一事实而无法正常显示或运行...

有两件事我想知道:

  • 是否有公开 WebBrowser 控件使用的呈现引擎的方法或类?
  • 为什么 DWORD Registry hack 不起作用,我该如何让它起作用?

为了清楚起见,我去了注册表,查找:HKEY LOCAL MACHINE > SOFTWARE > MICROSOFT > INTERNET EXPLORER > MAIN > FEATURE CONTROL > FEATURE_BROWSER_EMULATION 并添加了一个值 myApp.exe11000 的 DWORD。

根据http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation,11000 是让它使用 IE11 进行渲染。

【问题讨论】:

    标签: c# .net windows winforms internet-explorer


    【解决方案1】:

    您需要在主(64 位)节点和 32 位节点下添加注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl

    然后您应该访问http://webdbg.com/ua.aspx 以验证文档模式和UA 字符串。

    【讨论】:

    • 做到了!谢谢@EricLaw。在你的回答出现之前,我已经放弃了这个项目。谢谢!
    【解决方案2】:

    这里是我通常使用并为我工作的方法(适用于 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();
            }
    
    
        }
    

    【讨论】:

      猜你喜欢
      • 2011-08-07
      • 2012-10-06
      • 2019-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 2016-02-11
      • 2012-11-07
      相关资源
      最近更新 更多