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.