简体   繁体   English

WebBrowser控件使用IE9

[英]WebBrowser control to use IE9

I want that the WebBrowser control to use IE9. 我希望WebBrowser控件使用IE9。 IE9 is installed on the computer, but the WebBrowser control is still using IE8. IE9安装在计算机上,但WebBrowser控件仍在使用IE8。

I verified with http://www.whatbrowser.org/en/ . 我通过http://www.whatbrowser.org/en/进行了验证。 I try to make some changes to the registry (found a solution here) but is not working. 我尝试对注册表进行一些更改(在这里找到解决方案)但是没有用。

I think it is the user agent string that is being passed to the site. 我认为这是传递给网站的用户代理字符串。 It is misidentifying it as IE8 as it might not be meeting the requirements in their logic to match as IE9. 它错误地将其识别为IE8,因为它可能无法满足其逻辑中与IE9匹配的要求。 I can see the same thing happen on my box as well. 我也能看到同样的事情发生在我的盒子上。 You could specify the user agent string to use if you want. 您可以根据需要指定要使用的用户代理字符串。 Add this to your project 将其添加到您的项目中

In your using statements add ... 在你的using语句中添加...

using System.Runtime.InteropServices;

Within your form class add .... 在你的表单类中添加....

[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);
}

Then just call it somewhere in your code ... maybe the constructor, or the form_load event. 然后只需在代码中的某处调用它......也许是构造函数或form_load事件。

ChangeUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");

Browsers lie about their "user agent" to give web sites a break. 浏览器谎称他们的“用户代理”让网站中断。 You're running 9, you cannot have 8 and 9 installed at the same time unless you used the beta version. 您运行9,除非您使用测试版,否则不能同时安装8和9。 See this blog post for details about the user agent string. 有关用户代理字符串的详细信息,请参阅此博客文章

If you want to make sure then look at the DLL version that gets loaded. 如果您想确定然后查看加载的DLL版本。 Project + Properties, Debug, tick "Unmanaged code debugging". Project + Properties,Debug,勾选“Unmanaged code debugging”。 Start your program, Debug + Break All. 启动程序,Debug + Break All。 Debug + Windows + Modules and locate ieframe.dll in the list. 调试+ Windows +模块并在列表中找到ieframe.dll。 The version number column should tell you. 版本号列应该告诉您。 I'm getting "8.00.7600.16385 (win7_rtm.090713-1255)", the Win7 release version. 我得到了“8.00.7600.16385(win7_rtm.090713-1255)”,Win7发布版本。 I don't have IE9 installed yet. 我还没有安装IE9。

Use this in the HTML head: 在HTML头中使用它:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

Otherwise: 除此以外:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION\\yourexename.exe - REG_DWORD = 9000 (decimal) HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Internet Explorer \\ MAIN \\ FeatureControl \\ FEATURE_BROWSER_EMULATION \\ yourexename.exe - REG_DWORD = 9000(十进制)

You can try to add registry value that informs your WebBrowser control witch version of IE you would like to run for your application. 您可以尝试添加注册表值,以通知您希望为您的应用程序运行的WebBrowser控件的IE版本。

I had similar problem - more here 我有类似的问题 - 更多在这里

It seems it might be your page detection script. 它似乎可能是您的页面检测脚本。 Try this site (http://www.whatismybrowser.com/) . 试试这个网站(http://www.whatismybrowser.com/) I know other sites gave me the wrong information, but this site correctly identified the browser as the version of IE that was installed on my machine. 我知道其他网站给了我错误的信息,但是这个网站正确地将浏览器识别为我机器上安装的IE版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM