5

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
user689792
  • 291
  • 2
  • 4
  • 5

5 Answers5

7

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)");
Davin Studer
  • 1,501
  • 3
  • 15
  • 28
  • 1
    Actually it looks like this is happening. You can fix it by adding a registry value. http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control – Davin Studer Oct 12 '11 at 23:15
  • Thanks - Changed the version by User Agent - but the control is behaving like ie8 or 7 - because it is not working out HTML5 feature which if i test on standalone IE9, works fine. – hB0 Nov 24 '11 at 10:28
  • Like I said in my comment to my post I believe the is is not actually the user agent string, but the fact that the WebBrowser control defaults to IE7 rendering mode unless you tell it otherwise by a registry setting. – Davin Studer Dec 02 '11 at 20:43
  • 1
    Do this to turn on IE9 standards mode all the time and to enable GPU acceleration. `Make a DWORD value under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION. Set the key as YourAppName.exe. Set the value as 39321. Make a DWORD value under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_GPU_RENDERING. Set the key as YourAppName.exe. Set the value as 1` – Davin Studer Dec 02 '11 at 20:50
6

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    if I go with the real browser is showing correctly IE9, if I go with the webbrowser component is showing IE8. I know what is, and how to use a user agent. The IE browser, IE9, contain every previous versions, for compatibility mode, and webbrowser component use IE8, even if in registry I set to IE9 the "feature browser emulation" Also with the browser I don't have javascript errors and with the webbrowser component I have javascript errors – user689792 Apr 03 '11 at 20:39
  • Thank you for your answer. Can you explain me in more details the operations: "Debug + Windows + Modules and locate ieframe.dll in the list." I located others *.dll but not ieframe.dll. I try test with a very simple code: private void button1_Click(object sender, EventArgs e) { webBrowser1.Navigate("http://www.whatbrowser.org/en/"); } – user689792 Apr 03 '11 at 22:03
  • Strong sign that you've got IE9 loaded. mshtml.dll would be another. – Hans Passant Apr 03 '11 at 22:12
6

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)

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
hB0
  • 1,977
  • 1
  • 27
  • 33
1

You can try to add registry value that informs your WebBrowser control witch version of IE you would like to run for your application.

I had similar problem - more here

Community
  • 1
  • 1
Przemysław Michalski
  • 9,627
  • 7
  • 31
  • 37
0

It seems it might be your page detection script. Try this site (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.

cjbarth
  • 4,189
  • 6
  • 43
  • 62