Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser control to use IE9

I want that the WebBrowser control to use IE9. IE9 is installed on the computer, but the WebBrowser control is still using IE8.

I verified with http://www.whatbrowser.org/en/. I try to make some changes to the registry (found a solution here) but is not working.

like image 287
user689792 Avatar asked Apr 03 '11 18:04

user689792


3 Answers

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. 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 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.

ChangeUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
like image 131
Davin Studer Avatar answered Oct 20 '22 22:10

Davin Studer


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. 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. Project + Properties, Debug, tick "Unmanaged code debugging". Start your program, Debug + Break All. Debug + Windows + Modules and locate ieframe.dll in the list. The version number column should tell you. I'm getting "8.00.7600.16385 (win7_rtm.090713-1255)", the Win7 release version. I don't have IE9 installed yet.

like image 6
Hans Passant Avatar answered Oct 20 '22 22:10

Hans Passant


Use this in the HTML head:

<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)

like image 6
hB0 Avatar answered Oct 20 '22 23:10

hB0