[英]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.