J'ai vu la réponse de Veer. Je pense que c'est juste, mais cela n'a pas fonctionné pour moi. Peut-être que j'utilise .NET 4 et que j'utilise 64x OS, veuillez donc vérifier ceci.
Vous pouvez mettre en place le setup ou le vérifier au démarrage de votre application:
private void Form1_Load(object sender, EventArgs e)
{
var appName = Process.GetCurrentProcess().ProcessName + ".exe";
SetIE8KeyforWebBrowserControl(appName);
}
private void SetIE8KeyforWebBrowserControl(string appName)
{
RegistryKey Regkey = null;
try
{
if (Environment.Is64BitOperatingSystem)
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
else
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
if (Regkey == null)
{
MessageBox.Show("Application Settings Failed - Address Not found");
return;
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == "8000")
{
MessageBox.Show("Required Application Settings Present");
Regkey.Close();
return;
}
if (string.IsNullOrEmpty(FindAppkey))
Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == "8000")
MessageBox.Show("Application Settings Applied Successfully");
else
MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);
}
catch (Exception ex)
{
MessageBox.Show("Application Settings Failed");
MessageBox.Show(ex.Message);
}
finally
{
if (Regkey != null)
Regkey.Close();
}
}
Vous pouvez trouver messagebox.show, juste pour le test.
Les clés sont les suivantes:
11001 (0x2AF9) - Internet Explorer 11. Les pages Web sont affichées en mode périphérique IE11, quelle que soit la !DOCTYPE
directive.
11000 (0x2AF8) - Internet Explorer 11. Les pages Web contenant des !DOCTYPE
directives basées sur des normes sont affichées en mode périphérique IE11. Valeur par défaut pour IE11.
10001 (0x2711) - Internet Explorer 10. Les pages Web sont affichées en mode Normes IE10, quelle que soit la !DOCTYPE
directive.
10000 (0x2710) - Internet Explorer 10. Les pages Web contenant des !DOCTYPE
directives normalisées
s'affichent en mode Normes IE10. Valeur par défaut pour Internet Explorer 10.
9999 (0x270F) - Internet Explorer 9. Les pages Web sont affichées en mode Normes IE9, quelle que soit la !DOCTYPE
directive.
9000 (0x2328) - Internet Explorer 9. Les pages Web contenant des !DOCTYPE
directives basées sur des normes sont affichées en mode IE9.
8888 (0x22B8) - Les pages Web sont affichées en mode Normes IE8, quelle que soit la !DOCTYPE
directive.
8000 (0x1F40) - Les pages Web contenant des !DOCTYPE
directives normalisées sont affichées en mode IE8.
7000 (0x1B58) - Les pages Web contenant des !DOCTYPE
directives basées sur des normes sont affichées en mode Normes IE7.
Référence: MSDN: Contrôles des fonctionnalités Internet
J'ai vu des applications comme Skype utiliser 10001. Je ne sais pas.
REMARQUE
L'application d'installation modifiera le registre. Vous devrez peut-être ajouter une ligne dans le fichier manifeste pour éviter les erreurs dues aux autorisations de modification dans le registre:
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
MISE À JOUR 1
C'est une classe qui obtiendra la dernière version d'IE sous Windows et apportera les modifications nécessaires;
public class WebBrowserHelper
{
public static int GetEmbVersion()
{
int ieVer = GetBrowserVersion();
if (ieVer > 9)
return ieVer * 1000 + 1;
if (ieVer > 7)
return ieVer * 1111;
return 7000;
}
public static void FixBrowserVersion()
{
string appName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);
FixBrowserVersion(appName);
}
public static void FixBrowserVersion(string appName)
{
FixBrowserVersion(appName, GetEmbVersion());
}
public static void FixBrowserVersion(string appName, int ieVer)
{
FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName + ".exe", ieVer);
FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName + ".exe", ieVer);
FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName + ".vshost.exe", ieVer);
FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName + ".vshost.exe", ieVer);
}
private static void FixBrowserVersion_Internal(string root, string appName, int ieVer)
{
try
{
if (Environment.Is64BitOperatingSystem)
Microsoft.Win32.Registry.SetValue(root + @"\Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", appName, ieVer);
else
Microsoft.Win32.Registry.SetValue(root + @"\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", appName, ieVer);
}
catch (Exception)
{
}
}
public static int GetBrowserVersion()
{
string strKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer";
string[] ls = new string[] { "svcVersion", "svcUpdateVersion", "Version", "W2kVersion" };
int maxVer = 0;
for (int i = 0; i < ls.Length; ++i)
{
object objVal = Microsoft.Win32.Registry.GetValue(strKeyPath, ls[i], "0");
string strVal = System.Convert.ToString(objVal);
if (strVal != null)
{
int iPos = strVal.IndexOf('.');
if (iPos > 0)
strVal = strVal.Substring(0, iPos);
int res = 0;
if (int.TryParse(strVal, out res))
maxVer = Math.Max(maxVer, res);
}
}
return maxVer;
}
}
utilisation de la classe comme suit
WebBrowserHelper.FixBrowserVersion();
WebBrowserHelper.FixBrowserVersion("SomeAppName");
WebBrowserHelper.FixBrowserVersion("SomeAppName",intIeVer);
vous pouvez rencontrer un problème pour la comparabilité de Windows 10, peut-être en raison de votre site Web lui-même, vous devrez peut-être ajouter cette balise meta
<meta http-equiv="X-UA-Compatible" content="IE=11" >
Prendre plaisir :)
Environment.Is64BitOperatingSystem
pourEnvironment.Is64BitProcess
.Wow6432Node
sous - clé. Votre application n'a rien à faire de plus pour s'adapter à cette «nouvelle» clé.Utilisation des valeurs de MSDN :
int BrowserVer, RegVal; // get the installed IE version using (WebBrowser Wb = new WebBrowser()) BrowserVer = Wb.Version.Major; // set the appropriate IE version if (BrowserVer >= 11) RegVal = 11001; else if (BrowserVer == 10) RegVal = 10001; else if (BrowserVer == 9) RegVal = 9999; else if (BrowserVer == 8) RegVal = 8888; else RegVal = 7000; // set the actual key using (RegistryKey Key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree)) if (Key.GetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe") == null) Key.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe", RegVal, RegistryValueKind.DWord);
la source
CreateSubKey
devrait être utilisé à la place deOpenSubKey
puisque OpenSubKey retournera null si la clé n'existe pas.var appName = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe"; using (var Key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true)) Key.SetValue(appName, 99999, RegistryValueKind.DWord);
D'après ce que j'ai lu ici ( Contrôle de la compatibilité des contrôles WebBrowser :
Le plus simple est de mettre un nombre décimal très élevé ...
la source
SOFTWARE\WOW6432Node\Microsoft...
. Il est automatiquement redirigé dans le code, mais pourrait vous surprendre si vous ouvrez regedit.Registry.LocalMachine.OpenSubKey("..
travaillé sur le serveur Win2012 en tant qu'administrateur.Vous pouvez essayer ce lien
try { var IEVAlue = 9000; // can be: 9999 , 9000, 8888, 8000, 7000 var targetApplication = Processes.getCurrentProcessName() + ".exe"; var localMachine = Registry.LocalMachine; var parentKeyLocation = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"; var keyName = "FEATURE_BROWSER_EMULATION"; "opening up Key: {0} at {1}".info(keyName, parentKeyLocation); var subKey = localMachine.getOrCreateSubKey(parentKeyLocation,keyName,true); subKey.SetValue(targetApplication, IEVAlue,RegistryValueKind.DWord); return "all done, now try it on a new process".info(); } catch(Exception ex) { ex.log(); "NOTE: you need to run this under no UAC".info(); }
la source
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer
mais cette façon est plus simple. merciProcesses.getCurrentProcessName()
? Peut-êtreProcess.GetCurrentProcess().ProcessName
?Plutôt que de changer la RegKey, j'ai pu mettre une ligne dans l'en-tête de mon HTML:
<html> <head> <!-- Use lastest version of Internet Explorer --> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!-- Insert other header tags here --> </head> ... </html>
Voir Contrôle du navigateur Web et spécification de la version d'IE .
la source
FEATURE_BROWSER_EMULATION
technique, j'obtiens alorsMozilla/5.0 (Windows NT 6.2; Win64; x64; ...
que, avec laX-UA-Compatible
technique, j'obtiensMozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; ...
, que Google Analytics détecte comme un mobile.Voici la méthode que j'utilise habituellement et fonctionne pour moi (à la fois pour les applications 32 bits et 64 bits; ie_emulation peut être n'importe qui documenté ici: Contrôles de fonctionnalités Internet (B..C), émulation de navigateur ):
[STAThread] static void Main() { if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false)) { // Another application instance is running return; } try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe"; int ie_emulation = 10000; try { string tmp = Properties.Settings.Default.ie_emulation; ie_emulation = int.Parse(tmp); } catch { } SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation); m_webLoader = new FormMain(); Application.Run(m_webLoader); } finally { mutex.ReleaseMutex(); } } private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval) { RegistryKey Regkey = null; try { Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true); // If the path is not correct or // if user haven't privileges to access the registry if (Regkey == null) { YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found"); return; } string FindAppkey = Convert.ToString(Regkey.GetValue(appName)); // Check if key is already present if (FindAppkey == "" + ieval) { YukLoggerObj.logInfoMsg("Application FEATURE_BROWSER_EMULATION already set to " + ieval); Regkey.Close(); return; } // If a key is not present or different from desired, add/modify the key, key value Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord); // Check for the key after adding FindAppkey = Convert.ToString(Regkey.GetValue(appName)); if (FindAppkey == "" + ieval) YukLoggerObj.logInfoMsg("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart"); else YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION setting failed; current value is " + ieval); } catch (Exception ex) { YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message); } finally { // Close the Registry if (Regkey != null) Regkey.Close(); } }
la source
J'ai pu implémenter la solution de Luca, mais j'ai dû faire quelques changements pour qu'elle fonctionne. Mon objectif était d'utiliser D3.js avec un contrôle de navigateur Web pour une application Windows Forms (ciblant .NET 2.0). Cela fonctionne pour moi maintenant. J'espère que cela peut aider quelqu'un d'autre.
using System; using System.Collections.Generic; using System.Windows.Forms; using System.Threading; using Microsoft.Win32; using System.Diagnostics; namespace ClientUI { static class Program { static Mutex mutex = new System.Threading.Mutex(false, "jMutex"); /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false)) { // Another application instance is running return; } try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe"; int ie_emulation = 11999; try { string tmp = Properties.Settings.Default.ie_emulation; ie_emulation = int.Parse(tmp); } catch { } SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation); Application.Run(new MainForm()); } finally { mutex.ReleaseMutex(); } } private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval) { RegistryKey Regkey = null; try { Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true); // If the path is not correct or // if user doesn't have privileges to access the registry if (Regkey == null) { MessageBox.Show("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found"); return; } string FindAppkey = Convert.ToString(Regkey.GetValue(appName)); // Check if key is already present if (FindAppkey == ieval.ToString()) { MessageBox.Show("Application FEATURE_BROWSER_EMULATION already set to " + ieval); Regkey.Close(); return; } // If key is not present or different from desired, add/modify the key , key value Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord); // Check for the key after adding FindAppkey = Convert.ToString(Regkey.GetValue(appName)); if (FindAppkey == ieval.ToString()) { MessageBox.Show("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart"); } else { MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; current value is " + ieval); } } catch (Exception ex) { MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message); } finally { //Close the Registry if (Regkey != null) Regkey.Close(); } } } }
De plus, j'ai ajouté une chaîne (ie_emulation) aux paramètres du projet avec la valeur 11999. Cette valeur semble fonctionner pour IE11 (11.0.15).
Ensuite, j'ai dû modifier l'autorisation de mon application pour autoriser l'accès au registre. Cela peut être fait en ajoutant un nouvel élément à votre projet (à l'aide de VS2012). Sous les éléments généraux, sélectionnez fichier manifeste de l'application. Changez le niveau de asInvoker à requireAdministrator (comme indiqué ci-dessous).
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Si quelqu'un qui lit ceci essaie d'utiliser D3.js avec un contrôle de navigateur Web, vous devrez peut-être modifier les données JSON à stocker dans une variable à l'intérieur de votre page HTML car D3.json utilise XmlHttpRequest (plus facile à utiliser avec un serveur Web). Après ces changements et ce qui précède, mes formulaires Windows sont capables de charger des fichiers HTML locaux qui appellent D3.
la source
Combinez les réponses de RooiWillie et MohD
et n'oubliez pas d'exécuter votre application avec le droit administratif.
var appName = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe"; RegistryKey Regkey = null; try { int BrowserVer, RegVal; // get the installed IE version using (WebBrowser Wb = new WebBrowser()) BrowserVer = Wb.Version.Major; // set the appropriate IE version if (BrowserVer >= 11) RegVal = 11001; else if (BrowserVer == 10) RegVal = 10001; else if (BrowserVer == 9) RegVal = 9999; else if (BrowserVer == 8) RegVal = 8888; else RegVal = 7000; //For 64 bit Machine if (Environment.Is64BitOperatingSystem) Regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true); else //For 32 bit Machine Regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true); //If the path is not correct or //If user't have priviledges to access registry if (Regkey == null) { MessageBox.Show("Registry Key for setting IE WebBrowser Rendering Address Not found. Try run the program with administrator's right."); return; } string FindAppkey = Convert.ToString(Regkey.GetValue(appName)); //Check if key is already present if (FindAppkey == RegVal.ToString()) { Regkey.Close(); return; } Regkey.SetValue(appName, RegVal, RegistryValueKind.DWord); } catch (Exception ex) { MessageBox.Show("Registry Key for setting IE WebBrowser Rendering failed to setup"); MessageBox.Show(ex.Message); } finally { //Close the Registry if (Regkey != null) Regkey.Close(); }
la source
ajouter simplement ce qui suit à votre html fait l'affaire pas besoin de paramètres de registre
<meta http-equiv="X-UA-Compatible" content="IE=11" >
la source
Version Visual Basic:
Private Sub setRegisterForWebBrowser() Dim appName = Process.GetCurrentProcess().ProcessName + ".exe" SetIE8KeyforWebBrowserControl(appName) End Sub Private Sub SetIE8KeyforWebBrowserControl(appName As String) 'ref: http://stackoverflow.com/questions/17922308/use-latest-version-of-ie-in-webbrowser-control Dim Regkey As RegistryKey = Nothing Dim lgValue As Long = 8000 Dim strValue As Long = lgValue.ToString() Try 'For 64 bit Machine If (Environment.Is64BitOperatingSystem) Then Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", True) Else 'For 32 bit Machine Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", True) End If 'If the path Is Not correct Or 'If user't have priviledges to access registry If (Regkey Is Nothing) Then MessageBox.Show("Application Settings Failed - Address Not found") Return End If Dim FindAppkey As String = Convert.ToString(Regkey.GetValue(appName)) 'Check if key Is already present If (FindAppkey = strValue) Then MessageBox.Show("Required Application Settings Present") Regkey.Close() Return End If 'If key Is Not present add the key , Kev value 8000-Decimal If (String.IsNullOrEmpty(FindAppkey)) Then ' Regkey.SetValue(appName, BitConverter.GetBytes(&H1F40), RegistryValueKind.DWord) Regkey.SetValue(appName, lgValue, RegistryValueKind.DWord) 'check for the key after adding FindAppkey = Convert.ToString(Regkey.GetValue(appName)) End If If (FindAppkey = strValue) Then MessageBox.Show("Registre de l'application appliquée avec succès") Else MessageBox.Show("Échec du paramètrage du registre, Ref: " + FindAppkey) End If Catch ex As Exception MessageBox.Show("Application Settings Failed") MessageBox.Show(ex.Message) Finally 'Close the Registry If (Not Regkey Is Nothing) Then Regkey.Close() End If End Try End Sub
la source
Je sais que cela a été publié mais voici une version actuelle de dotnet 4.5 ci-dessus que j'utilise. Je recommande d'utiliser l'émulation de navigateur par défaut respectant doctype
InternetExplorerFeatureControl.Instance.BrowserEmulation = DocumentMode.DefaultRespectDocType;
internal class InternetExplorerFeatureControl { private static readonly Lazy<InternetExplorerFeatureControl> LazyInstance = new Lazy<InternetExplorerFeatureControl>(() => new InternetExplorerFeatureControl()); private const string RegistryLocation = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl"; private readonly RegistryView _registryView = Environment.Is64BitOperatingSystem && Environment.Is64BitProcess ? RegistryView.Registry64 : RegistryView.Registry32; private readonly string _processName; private readonly Version _version; #region Feature Control Strings (A) private const string FeatureRestrictAboutProtocolIe7 = @"FEATURE_RESTRICT_ABOUT_PROTOCOL_IE7"; private const string FeatureRestrictAboutProtocol = @"FEATURE_RESTRICT_ABOUT_PROTOCOL"; #endregion #region Feature Control Strings (B) private const string FeatureBrowserEmulation = @"FEATURE_BROWSER_EMULATION"; #endregion #region Feature Control Strings (G) private const string FeatureGpuRendering = @"FEATURE_GPU_RENDERING"; #endregion #region Feature Control Strings (L) private const string FeatureBlockLmzScript = @"FEATURE_BLOCK_LMZ_SCRIPT"; #endregion internal InternetExplorerFeatureControl() { _processName = $"{Process.GetCurrentProcess().ProcessName}.exe"; using (var webBrowser = new WebBrowser()) _version = webBrowser.Version; } internal static InternetExplorerFeatureControl Instance => LazyInstance.Value; internal RegistryHive RegistryHive { get; set; } = RegistryHive.CurrentUser; private int GetFeatureControl(string featureControl) { using (var currentUser = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, _registryView)) { using (var key = currentUser.CreateSubKey($"{RegistryLocation}\\{featureControl}", false)) { if (key.GetValue(_processName) is int value) { return value; } return -1; } } } private void SetFeatureControl(string featureControl, int value) { using (var currentUser = RegistryKey.OpenBaseKey(RegistryHive, _registryView)) { using (var key = currentUser.CreateSubKey($"{RegistryLocation}\\{featureControl}", true)) { key.SetValue(_processName, value, RegistryValueKind.DWord); } } } #region Internet Feature Controls (A) /// <summary> /// Windows Internet Explorer 8 and later. When enabled, feature disables the "about:" protocol. For security reasons, applications that host the WebBrowser Control are strongly encouraged to enable this feature. /// By default, this feature is enabled for Windows Internet Explorer and disabled for applications hosting the WebBrowser Control.To enable this feature using the registry, add the name of your executable file to the following setting. /// </summary> internal bool AboutProtocolRestriction { get { if (_version.Major < 8) throw new NotSupportedException($"{AboutProtocolRestriction} requires Internet Explorer 8 and Later."); var releaseVersion = new Version(8, 0, 6001, 18702); return Convert.ToBoolean(GetFeatureControl(_version >= releaseVersion ? FeatureRestrictAboutProtocolIe7 : FeatureRestrictAboutProtocol)); } set { if (_version.Major < 8) throw new NotSupportedException($"{AboutProtocolRestriction} requires Internet Explorer 8 and Later."); var releaseVersion = new Version(8, 0, 6001, 18702); SetFeatureControl(_version >= releaseVersion ? FeatureRestrictAboutProtocolIe7 : FeatureRestrictAboutProtocol, Convert.ToInt16(value)); } } #endregion #region Internet Feature Controls (B) /// <summary> /// Windows Internet Explorer 8 and later. Defines the default emulation mode for Internet Explorer and supports the following values. /// </summary> internal DocumentMode BrowserEmulation { get { if (_version.Major < 8) throw new NotSupportedException($"{nameof(BrowserEmulation)} requires Internet Explorer 8 and Later."); var value = GetFeatureControl(FeatureBrowserEmulation); if (Enum.IsDefined(typeof(DocumentMode), value)) { return (DocumentMode)value; } return DocumentMode.NotSet; } set { if (_version.Major < 8) throw new NotSupportedException($"{nameof(BrowserEmulation)} requires Internet Explorer 8 and Later."); var tmp = value; if (value == DocumentMode.DefaultRespectDocType) tmp = DefaultRespectDocType; else if (value == DocumentMode.DefaultOverrideDocType) tmp = DefaultOverrideDocType; SetFeatureControl(FeatureBrowserEmulation, (int)tmp); } } #endregion #region Internet Feature Controls (G) /// <summary> /// Internet Explorer 9. Enables Internet Explorer to use a graphics processing unit (GPU) to render content. This dramatically improves performance for webpages that are rich in graphics. /// By default, this feature is enabled for Internet Explorer and disabled for applications hosting the WebBrowser Control.To enable this feature by using the registry, add the name of your executable file to the following setting. /// Note: GPU rendering relies heavily on the quality of your video drivers. If you encounter problems running Internet Explorer with GPU rendering enabled, you should verify that your video drivers are up to date and that they support hardware accelerated graphics. /// </summary> internal bool GpuRendering { get { if (_version.Major < 9) throw new NotSupportedException($"{nameof(GpuRendering)} requires Internet Explorer 9 and Later."); return Convert.ToBoolean(GetFeatureControl(FeatureGpuRendering)); } set { if (_version.Major < 9) throw new NotSupportedException($"{nameof(GpuRendering)} requires Internet Explorer 9 and Later."); SetFeatureControl(FeatureGpuRendering, Convert.ToInt16(value)); } } #endregion #region Internet Feature Controls (L) /// <summary> /// Internet Explorer 7 and later. When enabled, feature allows scripts stored in the Local Machine zone to be run only in webpages loaded from the Local Machine zone or by webpages hosted by sites in the Trusted Sites list. For more information, see Security and Compatibility in Internet Explorer 7. /// By default, this feature is enabled for Internet Explorer and disabled for applications hosting the WebBrowser Control.To enable this feature by using the registry, add the name of your executable file to the following setting. /// </summary> internal bool LocalScriptBlocking { get { if (_version.Major < 7) throw new NotSupportedException($"{nameof(LocalScriptBlocking)} requires Internet Explorer 7 and Later."); return Convert.ToBoolean(GetFeatureControl(FeatureBlockLmzScript)); } set { if (_version.Major < 7) throw new NotSupportedException($"{nameof(LocalScriptBlocking)} requires Internet Explorer 7 and Later."); SetFeatureControl(FeatureBlockLmzScript, Convert.ToInt16(value)); } } #endregion private DocumentMode DefaultRespectDocType { get { if (_version.Major >= 11) return DocumentMode.InternetExplorer11RespectDocType; switch (_version.Major) { case 10: return DocumentMode.InternetExplorer10RespectDocType; case 9: return DocumentMode.InternetExplorer9RespectDocType; case 8: return DocumentMode.InternetExplorer8RespectDocType; default: throw new ArgumentOutOfRangeException(); } } } private DocumentMode DefaultOverrideDocType { get { if (_version.Major >= 11) return DocumentMode.InternetExplorer11OverrideDocType; switch (_version.Major) { case 10: return DocumentMode.InternetExplorer10OverrideDocType; case 9: return DocumentMode.InternetExplorer9OverrideDocType; case 8: return DocumentMode.InternetExplorer8OverrideDocType; default: throw new ArgumentOutOfRangeException(); } } } } internal enum DocumentMode { NotSet = -1, [Description("Webpages containing standards-based !DOCTYPE directives are displayed in IE latest installed version mode.")] DefaultRespectDocType, [Description("Webpages are displayed in IE latest installed version mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive could causes the page to load in Quirks.")] DefaultOverrideDocType, [Description( "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." )] InternetExplorer11OverrideDocType = 11001, [Description( "IE11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 edge mode. Default value for IE11." )] InternetExplorer11RespectDocType = 11000, [Description( "Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive." )] InternetExplorer10OverrideDocType = 10001, [Description( "Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10." )] InternetExplorer10RespectDocType = 10000, [Description( "Windows Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks." )] InternetExplorer9OverrideDocType = 9999, [Description( "Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.\r\n" + "Important In Internet Explorer 10, Webpages containing standards - based !DOCTYPE directives are displayed in IE10 Standards mode." )] InternetExplorer9RespectDocType = 9000, [Description( "Webpages are displayed in IE8 Standards mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks." )] InternetExplorer8OverrideDocType = 8888, [Description( "Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8\r\n" + "Important In Internet Explorer 10, Webpages containing standards - based !DOCTYPE directives are displayed in IE10 Standards mode." )] InternetExplorer8RespectDocType = 8000, [Description( "Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control." )] InternetExplorer7RespectDocType = 7000 }
la source
code
InternetExplorerFeatureControl.Instance.BrowserEmulation = DocumentMode.DefaultRespectDocType; ' Pour mieux comprendre où cela a été tiré, vous pouvez consulter msdn.microsoft.com/en-us/ieUne solution de contournement simple et peu coûteuse est que vous pouvez simplement mettre une valeur supérieure à 11001 dans la clé FEATURE_BROWSER_EMULATION. Ensuite, il prend le dernier IE disponible dans le système.
la source
Il est préférable de forcer le mode le plus élevé possible. Cela peut être accompli en ajoutant:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
et il est toujours bon d'inclure la bibliothèque polyfill afin de prendre en charge IE:
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
avant tout script.
la source