2 回答

TA貢獻1844條經驗 獲得超8個贊
默認情況下,Windows 窗體應用程序使用 IE 包裝器,并且不保證使用最新的 IE 版本。閱讀本文以了解 IE 包裝器背后發生的事情以及 Windows 仿真密鑰的作用。
我的一個舊項目中的這段代碼允許以編程方式為您的可執行進程更改 IE 的默認仿真版本:
private static readonly string BrowserEmulationRegistryKeyPath =
@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
/// <summary>
/// Add the process name to internet explorer emulation key
> /// i do this because the default IE wrapper dose not support the latest JS features
> /// Add process to emulation key and set a DWord value (11001) for it means we want use IE.11 as WebBrowser component
/// </summary>
public bool EmulateInternetExplorer()
{
using (
var browserEmulationKey = Registry.CurrentUser.OpenSubKey(BrowserEmulationRegistryKeyPath,
true))
{
if (browserEmulationKey == null)
Registry.CurrentUser.CreateSubKey(BrowserEmulationRegistryKeyPath);
string processName = $"{Process.GetCurrentProcess().ProcessName}.exe";
// Means emulation already added and we are ready to start
if (browserEmulationKey?.GetValue(processName) != null)
return true;
// Emulation key not exists and we must add it ( We return false because application restart to take effect of changes )
if (browserEmulationKey != null)
{
browserEmulationKey.SetValue(processName, 11001, RegistryValueKind.DWord);
browserEmulationKey.Flush();
}
return false;
}
}
如果您的網站無法在最新的 Internet Explorer(不兼容)中正確顯示,您應該使用其他 Web 瀏覽器包裝器,例如在您的 .Net 應用程序中嵌入 Chromium 的 cefSharp。
- 2 回答
- 0 關注
- 636 瀏覽
添加回答
舉報