winfrom中的webbrowser內核版本修改
阿新 • • 發佈:2019-01-24
filename pre reads clas open stand dia cli break
vs2008,winfrom中的webbrowser 其內核默認為IE7,當網頁中存在IE7不支持的屬性時回報錯。
private void Form1_Load(object sender, EventArgs e) { SetWebBrowserFeatures(11); } static void SetWebBrowserFeatures(int ieVersion) { // don‘t change the registryif running in-proc inside Visual Studio if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) return; //獲取程序及名稱 var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); //得到瀏覽器的模式的值 UInt32 ieMode = GeoEmulationModee(ieVersion); var featureControlRegKey = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\"; //設置瀏覽器對應用程序(appName)以什麽模式(ieMode)運行 Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION", appName, ieMode, RegistryValueKind.DWord); // enable the features which are "On" for the full Internet Explorer browser //不曉得設置有什麽用 Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", appName, 1, RegistryValueKind.DWord); } static int GetBrowserVersion() { int browserVersion = 0; using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues)) { var version = ieKey.GetValue("svcVersion"); if (null == version) { version = ieKey.GetValue("Version"); if (null == version) throw new ApplicationException("Microsoft Internet Explorer is required!"); } int.TryParse(version.ToString().Split(‘.‘)[0], out browserVersion); } //如果小於7 if (browserVersion < 7) { throw new ApplicationException("不支持的瀏覽器版本!"); } return browserVersion; } static UInt32 GeoEmulationModee(int browserVersion) { UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode. switch (browserVersion) { case 7: mode = 7000;break; case 8: mode = 8000;break; case 9: mode = 9000;break; case 10: mode = 10000;break; case 11: mode = 11000;break; } return mode; }
winfrom中的webbrowser內核版本修改