<Window x:Class="TestWPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:local="clr-namespace:TestWPF" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <TextBox x:Name="txt" AcceptsReturn="True" Height="40" VerticalAlignment="Top"/> <WindowsFormsHost HorizontalAlignment="Stretch" Margin="15,0,15,5" x:Name="wfHost"> <wf:WebBrowser x:Name="web"></wf:WebBrowser> </WindowsFormsHost> </Grid> </Window>
set IE version:
/// <summary> /// 定义IE版本的枚举 /// </summary> public enum IeVersion { //see https://docs.microsoft.com/zh-cn/previous-versions/windows/internet-explorer/ie-developer/general-info/ee330730(v=vs.85)?redirectedfrom=MSDN 强制ie11,//11001 (0x2AF9) 标准ie11,//11000 (0x2AF8) 强制ie10,//10001 (0x2711) Internet Explorer 10。网页以IE 10的标准模式展现,页面!DOCTYPE无效 标准ie10,//10000 (0x02710) Internet Explorer 10。在IE 10标准模式中按照网页上!DOCTYPE指令来显示网页。Internet Explorer 10 默认值。 强制ie9,//9999 (0x270F) Windows Internet Explorer 9. 强制IE9显示,忽略!DOCTYPE指令 标准ie9,//9000 (0x2328) Internet Explorer 9. Internet Explorer 9默认值,在IE9标准模式中按照网页上!DOCTYPE指令来显示网页。 强制ie8,//8888 (0x22B8) Internet Explorer 8,强制IE8标准模式显示,忽略!DOCTYPE指令 标准ie8,//8000 (0x1F40) Internet Explorer 8默认设置,在IE8标准模式中按照网页上!DOCTYPE指令展示网页 标准ie7//7000 (0x1B58) 使用WebBrowser Control控件的应用程序所使用的默认值,在IE7标准模式中按照网页上!DOCTYPE指令来展示网页 } /// <summary> /// 设置WebBrowser的默认版本 /// </summary> /// <param name="ver">IE版本</param> public static void SetIE(IeVersion ver) { string productName = AppDomain.CurrentDomain.SetupInformation.ApplicationName;//获取程序名称 object version; switch (ver) { case IeVersion.标准ie7: version = 0x1B58; break; case IeVersion.标准ie8: version = 0x1F40; break; case IeVersion.强制ie8: version = 0x22B8; break; case IeVersion.标准ie9: version = 0x2328; break; case IeVersion.强制ie9: version = 0x270F; break; case IeVersion.标准ie10: version = 0x02710; break; case IeVersion.强制ie10: version = 0x2711; break; case IeVersion.标准ie11: version = 0x2AF8; break; case IeVersion.强制ie11: version = 0x2AF9; break; default: version = 0x1F40; break; } RegistryKey key = Registry.CurrentUser; RegistryKey software = key.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\" + productName); if (software != null) { software.Close(); software.Dispose(); } RegistryKey reg = key.OpenSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true); //该项必须已存在 if (reg != null) reg.SetValue(productName, version, RegistryValueKind.DWord); }
call:
SetIE(IeVersion.标准ie11);