WebBrowser control to use IE9

12,330

Solution 1

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

Solution 2

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.

Solution 3

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)

Solution 4

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

Share:
12,330
user689792
Author by

user689792

Updated on June 04, 2022

Comments

  • user689792
    user689792 almost 2 years

    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.

  • user689792
    user689792 about 13 years
    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
    user689792 about 13 years
    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("whatbrowser.org/en/"); }
  • user1703401
    user1703401 about 13 years
    Strong sign that you've got IE9 loaded. mshtml.dll would be another.
  • Davin Studer
    Davin Studer over 12 years
    Actually it looks like this is happening. You can fix it by adding a registry value. stackoverflow.com/questions/4612255/…
  • hB0
    hB0 over 12 years
    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.
  • Davin Studer
    Davin Studer over 12 years
    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
    Davin Studer over 12 years
    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