c# - GeckoWebBrowser访问一个错误的URL,总是弹出消息框

标签 c# winforms geckofx

无法找到 www.addssds333fdsd.com.cn。请检查名称并重试。

 GeckoWebBrowser _webA = new GeckoWebBrowser();
 _webA.Navigate("www.addssds333fdsd.com.cn");

当我访问一个不正确的 URL 时,应用程序会弹出消息框。

如何捕获异常或删除消息框。

最佳答案

你需要实现 nsIPromptServcice2 和 nsIPrompt 接口(interface)

在那里你会得到一个方法列表(例如 Alert();),你只是不提供实现。 这将“捕获”异常。

创建下面的类(你需要提供一堆方法的实现,比如Alert、Confirm、Prompt等

public class FilteredPromptService : nsIPromptService2, nsIPrompt
{

    public void Alert(string dialogTitle, string text)
    {
         //do your stuff here
    } 
    //... other methods to follow
}

然后,在浏览器应用程序启动时的某处(如果是 WPF,可能在 Application_Startup() 中)分配提示服务:

PromptFactory.PromptServiceCreator = () => new FilteredPromptService();

另外,请注意上面的 PromptService 是静态的,因此这将应用于您应用程序中的所有 GeckoBrowser 实例。

关于c# - GeckoWebBrowser访问一个错误的URL,总是弹出消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40737542/

相关文章:

c# - 如何按总和的升序遍历所有大小为 K 的子集合。

c# - C# 中的小键盘键代码

javascript - 如何在 C# 中运行 GeckoFx "GetElementById"函数?

c# - 如何在 C# 中为 Gecko Browes 设置 Outhtml

c# - Reporting Services 2005 报告各部分后带有免责声明页面

c# - 将数据绑定(bind)到 ListView

c# - "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"

c# - 更改 DataGridView 中特定单元格的前景色

c# - 如何在 Windows 窗体应用程序中显示矢量图形 (SVG)?

zooming - 在 C# winforms 中缩放 geckoFX 内容