.Net 修改WebBrowser 内核版本

导读:本篇文章讲解 .Net 修改WebBrowser 内核版本,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

需求:在winform程序中,加载网页

做法:在窗口中添加一个panel,再从工具栏中拖入一个WebBroswer浏览器控件!

程序中调用webBroswer1.Navigate(URL); 即可加载网页

 该网站可以检查浏览器的内核版本:  http://gw.hncd.gov.cn/nboa/jsp/system/admin/browser_vali.jsp

但是在加载页面时有时会出现脚本错误!在谷歌浏览器上就不会,这是由于IE兼容性不好导致的!

解决方案一:提升内核版本,方法如下:

private static void WebBrowserVersionEmulation()
        {
            const string BROWSER_EMULATION_KEY =
            @”Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION”;
            //
            // app.exe and app.vshost.exe
            String appname = Process.GetCurrentProcess().ProcessName + “.exe”;
            //
            // Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
            const int browserEmulationMode = 11001;

            RegistryKey browserEmulationKey =
                Registry.CurrentUser.OpenSubKey(BROWSER_EMULATION_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
                Registry.CurrentUser.CreateSubKey(BROWSER_EMULATION_KEY);

            if (browserEmulationKey != null)
            {
                browserEmulationKey.SetValue(appname, browserEmulationMode, RegistryValueKind.DWord);
                browserEmulationKey.Close();
            }
        }

/*  IE各版本的值如下:

        11001 (0x2EDF) Internet Explorer 11. Webpages are displayed in IE11 Standards mode, regardless of the !DOCTYPE directive

        11000 (0x2AF8) :Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode

        10000 (0x2710) :Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

        10001 (0x2AF7) :Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive.

        9999 (0x270F) :Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.

        9000 (0x2328) :Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

        8888 (0x22B8) :Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.

        8000 (0x1F40) :Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.

        7000 (0x1B58) :Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
    */

注:IE浏览器的最高版本为IE 11。目前微软已经宣布放弃IE的开发,因此IE 11应该就是最后一个版本,以后应该不会再有更高版本了。

参考文章:

https://blog.csdn.net/cctvcqupt/article/details/47684909

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/51856.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!