簡體   English   中英

無法強制WebBrowser控件使用IE的當前版本進行呈現

[英]Cannot force WebBrowser Control to render using current version of IE

我需要Windows Forms應用程序中的WebBrowser控件,才能使用Internet Explorer的最新版本來呈現頁面,或者至少安裝在計算機上安裝的最新版本(即IE 11)。

幾周前,在我開始從事該項目之前,我遇到了一個名為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 ,使用IE11可以渲染11000。

您需要在主(64位)節點和32位節點下添加注冊表項,即HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl

然后,您應該訪問http://webdbg.com/ua.aspx以驗證文檔模式和UA字符串。

這是我通常使用並為我工作的方法(適用於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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM