C#.net WebBrowser不显示页面(浏览器不是最新的)

本文关键字:浏览器 最新 net WebBrowser 显示 | 更新日期: 2023-09-27 18:29:01

我正在为Ogame做一个迷你机器人。

我运行WebBrowser类,它说它是IE9(WebBrowser.Version)。

当我执行这个:

wb.Navigate(www.ogame.com.us);

上面写着:

"Your browser is not up to date."

然而,当我在Internet Explorer上启动页面时,它确实会显示网站。IE9是嵌入在.NETframework4.5VisualStudio'12中的WebBrowser吗<因为我不明白。有什么解决方案吗?>


提前谢谢。

C#.net WebBrowser不显示页面(浏览器不是最新的)

您的应用程序需要模拟不同版本的IE。这是通过注册表完成的。

internal class Helper
{
    public static void SetBrowserEmulation(
        string programName, IE browserVersion)
    {
        if (string.IsNullOrEmpty(programName))
        {
            programName = AppDomain.CurrentDomain.FriendlyName;
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey(
                "Software''Microsoft''Internet Explorer''Main" + 
                "''FeatureControl''FEATURE_BROWSER_EMULATION", true);
            if (regKey != null)
            {
                try
                {
                    regKey.SetValue(programName, browserVersion, 
                        RegistryValueKind.DWord);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error writing to the registry", ex);
                }
            }
            else
            {
                try
                {
                    regKey = Registry.CurrentUser.OpenSubKey("Software" + 
                        "''Microsoft''Internet Explorer''Main" + 
                        "''FeatureControl", true);
                    regKey.CreateSubKey("FEATURE_BROWSER_EMULATION");
                    regKey.SetValue(programName, browserVersion,
                        RegistryValueKind.DWord);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error accessing the registry", ex);
                }
            }
        }
    }
}
internal enum IE
{
    IE7 = 7000,
    IE8 = 8000,
    IE8StandardsMode = 8888,
    IE9 = 9000,
    IE9StandardsMode = 9999,
    IE10 = 10000,
    IE10StandardsMode = 10001
}

正在调用此方法。

Helper.SetBrowserEmulation(AppDomain.CurrentDomain.FriendlyName, IE.IE10);

你需要重新启动你的程序。