use*_*792 5 c# browser internet-explorer webbrowser-control internet-explorer-9
我希望WebBrowser控件使用IE9.IE9安装在计算机上,但WebBrowser控件仍在使用IE8.
我通过http://www.whatbrowser.org/en/进行了验证.我尝试对注册表进行一些更改(在这里找到解决方案)但是没有用.
我认为这是传递给网站的用户代理字符串.它错误地将其识别为IE8,因为它可能无法满足其逻辑中与IE9匹配的要求.我也能看到同样的事情发生在我的盒子上.您可以根据需要指定要使用的用户代理字符串.将其添加到您的项目中
在你的using语句中添加...
using System.Runtime.InteropServices;
Run Code Online (Sandbox Code Playgroud)
在你的表单类中添加....
[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(int dwOption, string pBuffer, int dwBufferLength, int dwReserved);
const int URLMON_OPTION_USERAGENT = 0x10000001;
public void ChangeUserAgent(String Agent)
{
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, Agent, Agent.Length, 0);
}
Run Code Online (Sandbox Code Playgroud)
然后只需在代码中的某处调用它......也许是构造函数或form_load事件.
ChangeUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
Run Code Online (Sandbox Code Playgroud)
在HTML头中使用它:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Run Code Online (Sandbox Code Playgroud)
除此以外:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION\yourexename.exe - REG_DWORD = 9000(十进制)