如何为Web浏览器默认设置IE9?

我正在用C#.NET开发一个应用程序。 我想将IE9版本用于WebBrowser; IE9是否安装在系统上。

是否有可能将IE9与WebBrower一起使用,可能是我的系统中没有安装IE9?

使用Windows Internet Explorer 8或更高版本,FEATURE_BROWSER_EMULATIONfunction定义Internet Explorer的默认模拟模式。 值9999 – 强制网页以IE9标准模式显示,而不管!DOCTYPE指令。 您需要在目标系统上安装IE9或更高版本。 检查Internetfunction控件(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(); } } 

插入

 "" 

进入你的html页面,但你必须知道Web_browser控件依赖于已安装在目标操作系统上的IE版本

为此,您必须查找

  • 什么是底层浏览器的版本(注册表项可能返回以前安装的版本)。 我使用的最简单的代码是询问WebBrowser控件

     Web浏览器浏览器=新的WebBrowser
    版本ver = browser.Version();  //使用ver.Major,您可以决定EMULATION
    

  • 应用程序的app-exe-name(在vs调试环境中运行时与“myapp”.vshost.exe不同)。 这个代码我找到了某个地方:

     //此代码检测.vshost。 在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());  //返回文件名部分
     }
    

  • 现在,您可以计算浏览器兼容性所必需的Registry-Entry。 Entry可以在Registry.LocalMachine(需要访问权限)或Registry.CurrentUser中。 我检查每个程序启动时的注册表,所以,我首先测试该条目是否存在

     string regSubKey = @“Software \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BROWSER_EMULATION”;
     string version =“”+ ver.Version +“0000”;  //已安装版本x 10000
     string appname = getAppExeName();
     RegistryKey rs = Registry.CurrentUser.OpenSubKey(regSubKey);
     keyval = rs.GetValue(appname);
     rs.Close();
     if(keyval!= null && keyval.ToString()。Equals(version))
         返回;  //已经完成,没有安装浏览器更新。
     //
     //为此应用和此版本创建密钥
     rs = Registry.LocalMachine.CreateSubKey(regSubKey);
     rs.SetValue(app,sversion,RegistryValueKind.DWord);
     rs.Flush();
     rs.Close();
    

  • 在64位+ 32位模式下,您可能还需要在“Software \ Wow6432Node”中创建一个条目

设置注册表项后,WebBrowser控件应以所需的模拟开始

不,webbrowser-element(我认为你的意思是这个)是基于IE6的。 你只能启动IE9的过程(不知道名字,但对于firefox它简单的“firefox.exe”)组成程序。

您可以从注册表中读取该版本:

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

要么

如果你有一个WebBrowser控件,你可以从那里抓取它:

 WebBrowser browser = new WebBrowser(); Version ver = browser.Version;