IE WebBrowser内核设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
public class IEVersion
{
/// <summary>
/// IE WebBrowser内核设置
/// </summary>
public static void BrowserEmulationSet()
{
//当前程序名称
var exeName = Process.GetCurrentProcess().ProcessName + ".exe";
//系统注册表信息
var mreg = Registry.LocalMachine;
//IE注册表信息
var ie = mreg.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree);
if (ie != null)
{
try
{
var val = ieVersionEmulation(ieVersion());
if (val != 0)
{
ie.SetValue(exeName, val);
}
mreg.Close();
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
}
 
/// <summary>
/// IE版本号
/// </summary>
/// <returns></returns>
static int ieVersion()
{
//IE版本号
RegistryKey mreg = Registry.LocalMachine;
mreg = mreg.CreateSubKey("SOFTWARE\\Microsoft\\Internet Explorer");
 
//更新版本
var svcVersion = mreg.GetValue("svcVersion");
if (svcVersion != null)
{
mreg.Close();
var v = svcVersion.ToString().Split('.')[0];
return int.Parse(v);
}
else
{
//默认版本
var ieVersion = mreg.GetValue("Version");
mreg.Close();
if (ieVersion != null)
{
var v = ieVersion.ToString().Split('.')[0];
return int.Parse(v);
}
}
return 0;
}
 
/// <summary>
/// 根据IE版本号 返回Emulation值
/// </summary>
/// <param name="ieVersion"></param>
/// <returns></returns>
static int ieVersionEmulation(int ieVersion)
{
//IE7 7000 (0x1B58)
if (ieVersion < 8)
{
return 0;
}
if (ieVersion == 8)
{
return 0x1F40;//8000 (0x1F40)、8888 (0x22B8)
}
if (ieVersion == 9)
{
return 0x2328;//9000 (0x2328)、9999 (0x270F)
}
else if (ieVersion == 10)
{
return 0x02710;//10000 (0x02710)、10001 (0x2711)
}
else if (ieVersion == 11)
{
return 0x2AF8;//11000 (0x2AF8)、11001 (0x2AF9
}
return 0;
}
}

  

本文作者:公众号python学习开发

本文链接:https://www.cnblogs.com/c-x-a/p/7261460.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   公众号python学习开发  阅读(471)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起