zoukankan      html  css  js  c++  java
  • WPF设置WebBrowser不弹JS报错框

            <Grid Name ="curGridBody" >
                <WebBrowser x:Name="ibbWeb"  Navigating="ibbWeb_Navigating">
                </WebBrowser>
           </Grid>

       /// <summary>
            /// 设置浏览器静默,不弹错误提示框
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void ibbWeb_Navigating(object sender, NavigatingCancelEventArgs e)
            {
                SetWebBrowserSilent(sender as WebBrowser, true);
            }

            /// <summary>  
            /// 设置浏览器静默,不弹错误提示框  
            /// </summary>  
            /// <param name="webBrowser">要设置的WebBrowser控件浏览器</param>  
            /// <param name="silent">是否静默</param>  
            private void SetWebBrowserSilent(WebBrowser webBrowser, bool silent)
            {
                try
                {
                    FieldInfo fi = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (fi != null)
                    {
                        object browser = fi.GetValue(webBrowser);
                        if (browser != null)
                            browser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, browser, new object[] { silent });
                    }
                }
                catch (Exception ex)
                {
                    LogInfo.saveLog("设置浏览器不弹错误提示框异常:" + ex);
                    return;
                }
            }

  • 相关阅读:
    string与stringbuilder的区别
    Web负载均衡的几种实现方式
    JS 禁用鼠标右键
    JS中的!=、== 、!==、===的用法和区别。
    SQL Server Change Tracking
    关于更新发布CSS和JS文件的缓存问题
    Authorization in Cloud Applications using AD Groups
    英语学习[ZZ]
    我奋斗了18年,不是为了和你一起喝咖啡
    我奋斗了18年才和你坐在一起喝咖啡
  • 原文地址:https://www.cnblogs.com/zty1294625258/p/8533723.html
Copyright © 2011-2022 走看看