1

I am developing an application in C#.NET. I want to use the IE9 version for WebBrowser; either IE9 is installed on system or not.

Is it possible that using IE9 with WebBrower and it may be that IE9 is not installed in my system?

apaderno
  • 28,547
  • 16
  • 75
  • 90
user2256721
  • 21
  • 1
  • 1
  • 2
  • Welcome to _Stackoverflow_. Did you tried anything to solve this problem? Show your effort first.. You can read [FAQ] and [ask] – Soner Gönül Apr 08 '13 at 08:31
  • What do you want to do open links in IE rather than their default browser ? or do you want a control you are using to use IE ? As to the version you will probably be stuck with what ever they have. – Mark Broadhurst Apr 08 '13 at 08:33

5 Answers5

9

With Windows Internet Explorer 8 or later the FEATURE_BROWSER_EMULATION feature defines the default emulation mode for Internet Explorer. Value 9999 - forces webpages to be displayed in IE9 Standards mode, regardless of the !DOCTYPE directive. You need IE9 or later installed on the target system. Check Internet Feature Controls (B..C)

private static void WebBrowserVersionEmulation()
{
    const string BROWSER_EMULATION_KEY = 
    @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
    //
    // app.exe and app.vshost.exe
    String appname = Process.GetCurrentProcess().ProcessName + ".exe";
    //
    // Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
    const int browserEmulationMode = 9999;

    RegistryKey browserEmulationKey =
        Registry.CurrentUser.OpenSubKey(BROWSER_EMULATION_KEY,RegistryKeyPermissionCheck.ReadWriteSubTree) ??
        Registry.CurrentUser.CreateSubKey(BROWSER_EMULATION_KEY);

    if (browserEmulationKey != null)
    {
        browserEmulationKey.SetValue(appname, browserEmulationMode, RegistryValueKind.DWord);
        browserEmulationKey.Close();
    }
}
BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
volody
  • 6,946
  • 3
  • 42
  • 54
  • Once you add that into your code, how do you actually use it? What do I put inside WebBrowserVersionEmulation(?) – DanMossa May 12 '15 at 05:24
  • 1
    @pshyoulost add this function to the application load – volody May 12 '15 at 19:42
  • Thanks for this! I was beating my head against a wall trying to get anything over IE8 working. Another tutorial told me to put this value in LocalMachine which was not working at all. This did the trick. – Justin Emlay Jul 15 '17 at 00:11
3

Insert

"<meta  http-equiv=\"X-UA-Compatible\" content=\"IE="\9\" >"

Into your html page,but you have to know Web_browser control dependent on version of IE that already installed on target OS

KF2
  • 9,887
  • 8
  • 44
  • 77
1

For this, you have to lookup

  • What is the version of the underlying browser (registry key may return former installed version). Simplest code I use is asking the WebBrowser control

    WebBrowser browser= new WebBrowser
    Version ver= browser.Version(); // With ver.Major you can decide the EMULATION
    

  • The app-exe-name of your app (differs, while running in vs debug environment to "myapp".vshost.exe). This code I found somewhere:

    // This code detects the .vshost. when running in vs ide
    [DllImport("kernel32.dll", SetLastError=true)]
    private static extern int GetModuleFileName([In]IntPtr hModule,
                                            [Out]StringBuilder lpFilename,
                                            [In][MarshalAs(UnmanagedType.U4)] int nSize);
    public static String getAppExeName()
    {
       StringBuilder appname= new StringBuilder(1024);
       GetModuleFileName(IntPtr.Zero, appname, appname.Capacity); 
       return Path.GetFileName(appname.ToString()); // return filename part
    }
    

  • Now, you can calculate the Registry-Entry which is necessary for the browser compatibility. The Entry may be in Registry.LocalMachine (access rights required) or Registry.CurrentUser. I check the registry on every program start, so, I first test the existence of the entry

    string regSubKey= @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
    string version= "" + ver.Version + "0000"; // installed version x 10000
    string appname= getAppExeName();
    RegistryKey rs = Registry.CurrentUser.OpenSubKey(regSubKey);
    keyval = rs.GetValue(appname);
    rs.Close();
    if (keyval != null && keyval.ToString().Equals(version))
         return;     // already done and no browser update installed.
    //
    // Create key for this app and this version
    rs = Registry.LocalMachine.CreateSubKey(regSubKey);
    rs.SetValue(app, sversion, RegistryValueKind.DWord);
    rs.Flush();
    rs.Close();
    

  • In 64bit + 32bit modes, may be you have to create an entry in "Software\Wow6432Node" too

After setting the registry key, the WebBrowser control should start with the required emulation

0

No, the webbrowser-element (I think you mean this) is on base of IE6. You only can start the process of IE9 (don't know the name but for firefox its simply "firefox.exe") form the program.

Iswanto San
  • 18,263
  • 13
  • 58
  • 79
jalgames
  • 781
  • 4
  • 23
0

You can read the version from the registry:

var ieVersion = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Internet Explorer").GetValue("Version");

or

If you have a WebBrowser control you can grab it from there:

WebBrowser  browser = new WebBrowser();
Version ver = browser.Version;
Gencebay
  • 61
  • 8
  • Hi Gencebay, thanks for reply. Actually the version is displaying 9.0 (when I am getting and above code) but the rendering HTML is not same as IE9. it's more than like IE8. Is there anyway that I can set the rendering version of WebBrowser? – user2256721 Apr 08 '13 at 09:51
  • 1
    you can try add the meta tag inside the tag of your HTML page. This meta tag must be added before any links to CSS, JavaScript files etc that are also in your to work properly though (only other tags or the tag can come before it). – Gencebay Apr 08 '13 at 10:07