可能还有其他项目,但如果你想走这条路线,这些是一些更受欢迎且活跃的项目,这应该可以为你提供一个开始。
WebBrowser控件可以呈现大多数网页,但默认情况下,它尝试以兼容模式呈现页面(基本上是IE7,因此会出现问题)。如果您正在构建自己的页面,只需在头部添加以下标签即可使其正常呈现...
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
然而,如果你正试图呈现一个无法添加标签的第三方网站,则事情变得更加困难。如上所述,如果只是在你自己的机器上,你可以使用注册表键(HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION)。
如果这两个选项都不可行,那么使用不同的浏览器控件(如上面提供的建议)几乎是你唯一的选择。
有一篇很棒的博客介绍了如何控制浏览器控件兼容模式:https://learn.microsoft.com/en-gb/archive/blogs/patricka/controlling-webbrowser-control-compatibility
您应该将程序名称添加到注册表HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION中,以便使用与普通互联网浏览器相同的最新功能。
对于我来说,值8000(0x1F40) - IE8模式可以解决许多脚本错误问题。
参考:
你甚至可以将注册表值设置为11000,以获得最新版本的IE!
private void Form1_Load(object sender, EventArgs e)
{
var appName = Process.GetCurrentProcess().ProcessName + ".exe";
SetIE8KeyforWebBrowserControl(appName);
webBrowser1.ScriptErrorsSuppressed = true;
}
private void SetIE8KeyforWebBrowserControl(string appName)
{
RegistryKey Regkey = null;
try
{
// For 64 bit machine
if (Environment.Is64BitOperatingSystem)
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
else //For 32 bit machine
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
// If the path is not correct or
// if the user haven't priviledges to access the registry
if (Regkey == null)
{
MessageBox.Show("Application Settings Failed - Address Not found");
return;
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
// Check if key is already present
if (FindAppkey == "8000")
{
MessageBox.Show("Required Application Settings Present");
Regkey.Close();
return;
}
// If a key is not present add the key, Key value 8000 (decimal)
if (string.IsNullOrEmpty(FindAppkey))
Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);
// Check for the key after adding
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == "8000")
MessageBox.Show("Application Settings Applied Successfully");
else
MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);
}
catch (Exception ex)
{
MessageBox.Show("Application Settings Failed");
MessageBox.Show(ex.Message);
}
finally
{
// Close the Registry
if (Regkey != null)
Regkey.Close();
}
}
webBrowser.ScriptErrorsSuppressed = true;
吗? - jomsk1e