😛

On this web page:

up to date Aug twenty sixth, 2016 – the unique was revealed in Could 2011

I exploit the Web Explorer Net Browser Management in a number of my desktop purposes to show doc content material. For instance Markdown Monster, Assist Builder and WebSurge rely closely on the Net Browser Management to render their doc centric and even wealthy interactive UI (within the case of Markdown Monster which hosts an HTML editor). Whether or not you are simply rendering doc content material, otherwise you’re interacting with wealthy interactive content material, HTML occurs to be one of the widespread doc codecs to show or work together with and it makes a beautiful addition to traditional varieties primarily based UI. Even in desktop purposes, is commonly method simpler than utilizing labels or edit containers and even a number of the WPF textual content containers. HTML is straightforward to generate, usually re-usable, and simply extensible and distributable. The Net Browser Management permits for an efficient strategy to show HTML in your purposes in a method that blends in and turns into a part of your utility.

However there is a snag: The Net Browser Management is – by default – perpetually caught in IE 7 rendering mode. Regardless that we’re now as much as IE 11 and a fairly HTML5 suitable browser, the Net Browser Management at all times makes use of the IE 7 rendering engine by default. It’s because the unique variations of the ActiveX management used this mode and for backwards compatibility the Management continues this outdated and really HTML5 unfriendly default.

This is applicable whether or not you’re utilizing the Net Browser management in a WPF utility, a WinForms app, or FoxPro utility utilizing the ActiveX management. Behind the scenes all these UI platforms use the identical COM interfaces and so that you’re caught with those self same guidelines.

The excellent news is there are a few methods to override the default rendering conduct:

  • Utilizing the IE X-UA-Appropriate Meta header
  • Utilizing Utility particular FEATURE_BROWSER_EMULATION Registry Keys

However first lets see the issue extra graphically.

Rendering Challenged

To see what I’m speaking about, listed below are two display screen pictures rendering an HTML5 web page that features some CSS3 performance – rounded corners and border shadows – from an earlier submit. One makes use of Web Explorer as a standalone browser, and one makes use of a easy WPF kind that features the Net Browser management.

Full IE Browser:

 

Net Browser Management in a WPF kind:

WebBrowserControlWpfForm

The the complete Web Explorer the web page shows the HTML appropriately – you see the rounded corners and shadow displayed. Clearly the latter rendering utilizing the Net Browser management in a WPF utility is a bit missing. Not solely are the brand new CSS options lacking however the web page additionally renders in Web Explorer’s quirks mode so all of the margins, padding and so on. behave otherwise by default, though there’s a CSS reset utilized on this web page. However the default IE 7 mode does not acknowledge many of those settings leading to a horrible render mode.

If you happen to’re constructing an utility that intends to make use of the Net Browser management for a dwell preview of some HTML that is clearly undesirable.

Utilizing the X-UA-Appropriate HTML Meta Tag

If you happen to management the content material in your Net Browser management by rendering the HTML pages you show your self, the best method to supply later variations of the IE rendering engine is through the use of the IE Edge mode header. By including a meta tag to the pinnacle of the HTML doc rendered within the Net Browser Management you may successfully override the IE Rendering engine and specify which model of IE (or the newest model) to make use of.

See also  Installing Oracle SQL Developer

The tag to make use of within the header appears like this:

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

Inside a full doc it appears like this:

<!DOCTYPE html> 
<html> 
  <head> 
    <meta http-equiv="X-UA-Compatible" content material="IE=edge" /> 
    ... different headers
  </head>
  <physique>
    ... content material
  </physique>
</html>

Be aware the header must be the primary header in order that the engine is utilized earlier than another headers are processed.

On this case IE=edge makes use of the present model of IE that’s put in on the machine. So when you have IE 11 put in that is used, if IE 10 is put in that is used.

You may also specify a selected model of IE:

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

For information on all of the modes accessible see this StackOverflow reply.

Alternately you too can serve X-UA-Appropriate: IE=edge as a uncooked HTTP header from a Net server, which has the identical conduct because the http-equiv meta header.

Caveats with the Edge Mode Header

There are some things you want with a view to use the meta tag and make it work correctly:

  • It’s a must to management the Web page
    To be able to add the <meta> tag you need to management the web page so to add the <meta> tag into your HTML. If you happen to’re rendering arbitrary HTML that does not embody the tag, then this strategy will not work clearly. Usually the header strategy works nice if you happen to generate your individual content material.

  • Browser Model Reporting is inaccurate
    The <meta> tag modifications the rendering engine conduct that IE makes use of, however it does not change the best way that IE stories its model. If you happen to entry pages that do IE model checking you will discover that it nonetheless factors at IE 7 (or someday some customized browser model) that does not mirror the present rendering mode. If you happen to’re operating script code which will depend on browser sniffing this will change into an issue. I bumped into this just lately with Ace Editor, which has a few odd locations the place it makes use of browser sniffing for coping with the clipboard, and that code would not work. That is doubtless an edge (ha ha) case, however bear in mind that this will change into an issue.

Function Delegation through Registry Hacks

One other and maybe extra strong strategy to have an effect on the Net Browser Management model is through the use of FEATURE_BROWSER_EMULATION. Beginning with IE 8 Microsoft launched registry entries that management browser conduct when a Net Browser Management is embedded into different purposes. These registry values are utilized by many utility in your system.

Basically you may specify a registry with the identify of your Executable and specify the model of IE that you just wish to load. The numbers are specified as 11000, 10000, 9000, 8000 and 7000. The keys will be specified both for the present person (HKCU) or globally for all customers (HKLM).

See also  Dragon Ball Xenoverse

This is what I’ve in my HKCU key:

Registry Settings in HKCU

Discover some large purposes like Visible Studio and Outlook use these overrides and on the HKLM keys additionally, you will discover apps like Skype SnagIt, Fiddler, SourceTree, 1Password and the Home windows Assist Viewer to call a number of. So this function is definitely utilized by a variety of standard software program.

Registry Key Location for FEATURE_BROWSER EMULATION

You possibly can specify these keys within the registry at:

HKEY_CURRENT_USERSOFTWAREMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION

The HKCU secret is one of the best place to set these values as a result of there is a single key and it may be set with out admin rights, however you too can set these keys on the machine degree at HKLM:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerMAINFeatureControlFEATURE_BROWSER_EMULATION

or for a 32 bit utility on a 64 bit machine:

HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION

Key Identify

The keyname is the EXE identify of your utility like:

  • outlook.exe
  • MarkdownMonster.exe

Values

The worth specifies the IE model as follows:

The worth to set this key to is (taken from MSDN right here) as decimal values:

11001 (0x2AF9)
Web Explorer 11. Webpages are displayed in IE11 Requirements mode, whatever the !DOCTYPE directive.

11000 (0x2AF8)
Web Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 mode.

10001 (0x2AF7)
Web Explorer 10. Webpages are displayed in IE10 Requirements mode, whatever the !DOCTYPE directive.

10000 (0x2710)
Web Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 mode.

9999 (0x270F)
Web Explorer 9. Webpages are displayed in IE9 Requirements mode, whatever the !DOCTYPE directive.

9000 (0x2328)
Web Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

8888 (0x22B8)
Webpages are displayed in IE8 Requirements mode, whatever the !DOCTYPE directive.

8000 (0x1F40)
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.

7000 (0x1B58)
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Requirements mode. This mode is type of pointless since it is the default.

Setting these keys allows your purposes to make use of the newest Web Explorer variations in your machine simply. Sadly there does not appear to be a key that claims use the newest model that is put in – you need to be particular relating to the model sadly. Provided that Home windows 7 and later can run IE 11, I am requiring customers to have IE 11 if I need to use HTML5 and extra superior CSS options like Flexbox, but when your content material is less complicated you may in all probability get away with utilizing IE 10 and even IE 9.

Don’t overlook so as to add Keys for Host Environments

As talked about above you need to specify the identify of the EXE you are operating as the important thing within the registry.

If you happen to’re utilizing a growth setting like Visible Studio or Visible FoxPro to debug your purposes, remember that your most important EXE you’re operating whereas debugging might not be the ultimate EXE that you’re constructing. So after you have arrange your registry keys, your debugging expertise should not see the improved rendering options within the Net Browser management since you’re not really operating the ultimate EXE.

See also  Mission 14 - The Barricade | Goo campaign - Grey Goo Game Guide

The issue is that whenever you debug in these environments, you’re operating a debugging host and to ensure that it to render correctly you will have to the host to the FEATURE_BROWSER_EMULATION keys as nicely.

For Visible Studio this will probably be yourapp.vshost.exe, which is the debugging host. For Visible FoxPro you will need vfp9.exe. Merely add these keys to the registry alongside these you utilize in your precise, dwell utility.

Registry Key Set up in your Utility

It’s vital to keep in mind that the registry settings from above are made per utility, so most certainly that is one thing you need to arrange together with your installer. I let my installers write the values into the registry throughout the set up course of which additionally removes the keys on uninstall.

Personally I at all times desire setting this worth per person utilizing utilizing the HKCU key which works for each 32 and 64 bit purposes in a single place.

If you happen to set the keys globally on HKLM for all customers, keep in mind that 32 and 64 bit settings require separate settings within the registry. So if you happen to’re creating your installer you probably will need to set each keys within the registry preemptively in your utility.

Set up

For example, I exploit InnoSetup for nearly all of my installs now which appears like this:

; IE 11 mode
Root: HKCU; Subkey: "SoftwareMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION"; ValueType: dword; ValueName: "MarkdownMonster.exe"; ValueData: "11001"; Flags: createvalueifdoesntexist

Different installer merchandise may even allow you to set up keys instantly.

Be aware that if you happen to use the HKEY_LOCAL_MACHINE key you too can add the registry keys instantly as a part of your utility when it begins up.

The next is .NET code, however it ought to provide you with an concept learn how to simply create the keys:

public static void EnsureBrowserEmulationEnabled(string exename = "MarkdownMonster.exe", bool uninstall = false)
{

    attempt
    {
        utilizing (
            var rk = Registry.CurrentUser.OpenSubKey(
                    @"SOFTWAREMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION", true)
        )
        {
            if (!uninstall)
            {
                dynamic worth = rk.GetValue(exename);
                if (worth == null)
                    rk.SetValue(exename, (uint)11001, RegistryValueKind.DWord);
            }
            else
                rk.DeleteValue(exename);
        }
    }
    catch
    {
    }
}

Abstract

It might be good if the Net Browser Management would simply use the native Web Explorer engine as is, however as you see on this article, that is sadly not the case and you need to coerce the browser. You probably have management over your paperwork that you just render within the Net Browser Management you could possibly use X-UA-Appropriate header in your pages. In any other case you need to resort to the registry hack utilizing FEATURE_BROWSER_EMULATION.

Personally I’ve used the registry hack for all of my apps that use the Net Browser Management as a result of my purposes are likely to render HTML from all types of various sources – native generated content material, in addition to Net loaded pages for previews and typically even dynamically injected content material. It is higher to pressure the newest IE model for all content material than overlook the very fact you want customized headers for different non-application content material you would possibly show (replace notices, registration varieties, notifications and so on.)

Today most machines will probably be operating both IE 10 or 11, so there’s a lot much less of an issue with differening browser conduct than there was once.

Leave a Reply

Your email address will not be published.