日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WebBrowser 设置IE兼容性

發(fā)布時(shí)間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WebBrowser 设置IE兼容性 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在窗體應(yīng)用程序和wpf程序中會(huì)使用到WebBrowser 來顯示一個(gè)網(wǎng)頁,但是可能要顯示的網(wǎng)頁要求在特定的模式下運(yùn)行,因此需要調(diào)整WebBrowser 對(duì)網(wǎng)頁兼容性的設(shè)置;

通過在注冊(cè)表中設(shè)置HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION中添加一個(gè)值,該值指示該程序以什么模式來運(yùn)行IE

代碼如下(下面代碼是復(fù)制別人,在這里是為了方便查找,有一些看不懂)

?/// <summary>/// 修改注冊(cè)表信息來兼容當(dāng)前程序///?/// </summary>static void SetWebBrowserFeatures(int ieVersion){// don't change the registry if running in-proc inside Visual Studioif (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\";//設(shè)置瀏覽器對(duì)應(yīng)用程序(appName)以什么模式(ieMode)運(yùn)行Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION",appName, ieMode, RegistryValueKind.DWord);// enable the features which are "On" for the full Internet Explorer browser//不曉得設(shè)置有什么用Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION",appName, 1, RegistryValueKind.DWord);//Registry.SetValue(featureControlRegKey + "FEATURE_AJAX_CONNECTIONEVENTS",// ? ?appName, 1, RegistryValueKind.DWord);//Registry.SetValue(featureControlRegKey + "FEATURE_GPU_RENDERING",// ? ?appName, 1, RegistryValueKind.DWord);//Registry.SetValue(featureControlRegKey + "FEATURE_WEBOC_DOCUMENT_ZOOM",// ? ?appName, 1, RegistryValueKind.DWord);//Registry.SetValue(featureControlRegKey + "FEATURE_NINPUT_LEGACYMODE",// ? ?appName, 0, RegistryValueKind.DWord);}/// <summary>/// 獲取瀏覽器的版本/// </summary>/// <returns></returns>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);}//如果小于7if (browserVersion < 7){throw new ApplicationException("不支持的瀏覽器版本!");}return browserVersion;}/// <summary>/// 通過版本得到瀏覽器模式的值/// </summary>/// <param name="browserVersion"></param>/// <returns></returns>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; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.?break;case 8:mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.?break;case 9:mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. ? ? ? ? ? ? ? ? ? ?break;case 10:mode = 10000; // Internet Explorer 10.break;case 11:mode = 11000; // Internet Explorer 11break;}return mode;}
在使用WebBrowser顯示一個(gè)兼容性要求的網(wǎng)頁時(shí),修改SetWebBrowserFeatures方法中后再顯示一個(gè)網(wǎng)頁即可,ieVersion為要兼容的IE的版本


總結(jié)

以上是生活随笔為你收集整理的WebBrowser 设置IE兼容性的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。