Thursday, May 12, 2016

How to Change Internet Explorer Document Mode of Web Browser Control

In your Windows Forms or WPF application, you may need to change document mode of your WebBrowser  Control.  One way  to do this  is  that  adding a registry record under


Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION


Here is the C# code,




public MainForm()
{
   WriteRegistry();
}
private void WriteRegistry()
{
   const string IERegPath = @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
   const string IEVersion = "11001";
   const string AppName = "MyTestApp.exe";

    RegistryKey Regkey = null;

     try
     {
          Regkey = Registry.CurrentUser.OpenSubKey(IERegPath, true);
          Regkey.SetValue(AppName,IEVersion, RegistryValueKind.DWord);
     }
     catch (Exception ex)
     {
          MessageBox.Show(ex.ToString());
     }
}        



Here we set IE Version  value as  11001 which means ; Internet Explorer 11. Webpages are displayed in IE11 edge mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.

You can find IE Version values here;
https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx

The reason that we added this register under CURRENT_USER instead of  LOCAL_MACHINE is that  writing a registery to LOCAL_MACHINE requires admin rights and the user who is using your application may not be administrator on the computer. That's why it is safer to add registry for only current user.

After running your application, you can see the registry value  as ;




Regards,


No comments:

Post a Comment