Created
January 30, 2015 23:16
-
-
Save kenwilcox/ce4da86f7264a85ff848 to your computer and use it in GitHub Desktop.
Setting IE Emulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.Win32; | |
using System.Windows.Forms; | |
namespace FixIE | |
{ | |
public class IEEmulation | |
{ | |
private static string DefaultName() | |
{ | |
return Application.ProductName + ".exe"; | |
} | |
public static string GetCurrentSetting() | |
{ | |
return GetCurrentSetting(DefaultName()); | |
} | |
public static string GetCurrentSetting(string applicationName) | |
{ | |
string version = String.Empty; | |
string rootKey = @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; | |
//App key | |
RegistryKey appKey = Registry.CurrentUser.CreateSubKey(rootKey);// + applicationName); | |
try | |
{ | |
RegistryValueKind k = appKey.GetValueKind(applicationName); | |
version = appKey.GetValue(applicationName).ToString(); | |
appKey.Close(); | |
} | |
catch | |
{ | |
appKey.Close(); | |
} | |
if (version.Equals(String.Empty)) version = "7000"; | |
return GetEmulationModes()[Int32.Parse(version)]; | |
} | |
public static void SetCurrentSetting(int value) | |
{ | |
SetCurrentSetting(DefaultName(), value); | |
} | |
public static void SetCurrentSetting(string applicationName, int value) | |
{ | |
string version = String.Empty; | |
string rootKey = @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; | |
//App key | |
RegistryKey appKey = Registry.CurrentUser.CreateSubKey(rootKey);// + applicationName); | |
try | |
{ | |
//RegistryValueKind k = appKey.GetValueKind(applicationName); | |
//version = appKey.GetValue(applicationName).ToString(); | |
appKey.SetValue(applicationName, value, RegistryValueKind.DWord); | |
appKey.Close(); | |
} | |
catch | |
{ | |
appKey.Close(); | |
} | |
} | |
// http://msdn.microsoft.com/en-us/library/ie/ee330730(v=vs.85).aspx | |
public static Dictionary<int, string> GetEmulationModes() | |
{ | |
Dictionary<int, string> ret = new Dictionary<int, string>(); | |
ret.Add(11001, "IE 11 - Edge Mode"); | |
ret.Add(11000, "IE 11 - Standards Mode"); | |
ret.Add(10001, "IE 10 - Edge Mode"); | |
ret.Add(10000, "IE 10 - Standards Mode"); | |
ret.Add(9999, "IE 9 - Edge Mode"); | |
ret.Add(9000, "IE 9 - Standards Mode*"); | |
ret.Add(8888, "IE 8 - Edge Mode"); | |
ret.Add(8000, "IE 8 - Standards Mode*"); | |
ret.Add(7000, "IE 7 - Standards Mode (Default Setting)"); | |
return ret; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment