wpf 兼容html5浏览器,wpf的webbrowser加载本地Html无法正常工作

Hi skczjun,

>>想请教下一般这种是不是Js不兼容webBrowser?

是的,默认情况下webBrowser会以比较底的IE内核运行(比如IE7,8)。这样你的网页中有些不支持的脚本或者其他就会没有办法正常运行。

你需要通过改变注册表来指定你程序的webBrowser运行IE的版本(比如最新IE11)。这样就可以正常运行。

你可以通过下面的代码来设定。

SetWebBrowserFeatures(11);//IE11

static void SetWebBrowserFeatures(int ieVersion)

{

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\";

Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION",

appName, ieMode, RegistryValueKind.DWord);

Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION",

appName, 1, RegistryValueKind.DWord);

}

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 11

break;

}

return mode;

}

Best Regards,

Yohann Lu

MSDN Community Support

Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to

MSDN Support, feel free to contact MSDNFSF@microsoft.com.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值