我正在尝试为 Ogame 制作一个迷你机器人。
我运行我的 WebBrowser 类,它说它是 IE9 (WebBrowser.Version)。
当我执行此操作时:
wb.Navigate(www.ogame.com.us);
它说:
"Your browser is not up to date."
但是,当我在 Internet Explorer 上启动该页面时,它会显示该站点。
是 VisualStudio '12 中使用 .NET Framework 4.5 嵌入的 WebBrowser IE9 吗?
因为我不明白。
有什么解决办法吗?
提前致谢。
最佳答案
您的应用程序需要模拟不同版本的 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);
您需要重新启动您的程序。
关于C# .net WebBrowser 不显示页面(浏览器不是最新的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18429602/