繁体   English   中英

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

[英]How to set IE9 by default for web browser?

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

是否可以将IE9与WebBrower一起使用,并且可能是系统中未安装IE9?

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

插入

"<meta  http-equiv=\"X-UA-Compatible\" content=\"IE="\9\" >"

进入html页面,但您必须了解Web_browser控件,该控件取决于目标操作系统上已安装的IE版本

为此,您必须查找

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

     WebBrowser browser= new WebBrowser Version ver= browser.Version(); // With ver.Major you can decide the EMULATION 

  • 应用程序的应用程序名称(在vs调试环境中运行时,与“ myapp” .vshost.exe不同)。 我在某处找到的代码:

     // This code detects the .vshost. when running in 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()); // return filename part } 

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

     string regSubKey= @"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION"; string version= "" + ver.Version + "0000"; // installed version x 10000 string appname= getAppExeName(); RegistryKey rs = Registry.CurrentUser.OpenSubKey(regSubKey); keyval = rs.GetValue(appname); rs.Close(); if (keyval != null && keyval.ToString().Equals(version)) return; // already done and no browser update installed. // // Create key for this app and this version rs = Registry.LocalMachine.CreateSubKey(regSubKey); rs.SetValue(app, sversion, RegistryValueKind.DWord); rs.Flush(); rs.Close(); 

  • 在64bit + 32bit模式下,可能您也必须在“ Software \\ Wow6432Node”中创建一个条目

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

不,网络浏览器元素(我想您是说这)是基于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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM