zoukankan      html  css  js  c++  java
  • Webbrowser控件中屏蔽弹出脚本错误对话框

    WebBrowser控件ScriptErrorsSuppressed
    设置为True,可禁止弹出脚本错误对话,ScriptErrorsSuppressed属性是对其基础COM控件的Silent属性的封装,因此设置ScriptErrorsSuppressed属性和设置其基础COM控件的Slient属性是效果一样的,这一点通过反编译System.Windows.Forms程序集可以证实。


    为了解决这个问题,有的人专门从WebBrowser派生出一个新类,然后重写了AttachInterfaces方法,其实也是没有必要的,效果和直接设置ScriptErrorsSuppressed属性相同。


    不过要注意的是:
    ScriptErrorsSuppressed 设置为True会禁用所有的对话,比如提示Activex下载、执行以及安全登录等对话
    如果不想禁止除脚本错误之外的对话,请使用MSDN上的代码示例:


    private void browser_DocumentCompleted(object sender,
    WebBrowserDocumentCompletedEventArgs e)
    {
        ((WebBrowser)sender).Document.Window.Error
    += new HtmlElementErrorEventHandler(Window_Error);
    }


    private void Window_Error(object sender, HtmlElementErrorEventArgs
    e)
    {
        // Ignore the error and suppress the error dialog box.
       
    e.Handled = true;
    }

  • 相关阅读:
    final、static关键字
    this关键字与super关键字区别
    JAVA常见报错
    Java抽象类和多态
    Java 类和接口的继承
    JAVA封装
    库存管理案例
    Map的遍历
    LinkedList vector集合,Set接口
    Collection,迭代器iterator,list接口
  • 原文地址:https://www.cnblogs.com/qqflying/p/2607881.html
Copyright © 2011-2022 走看看