GeckoWebBrowser 访问错误的 URL,总是弹出消息框 [英] GeckoWebBrowser access an incorrect URL,Always pop up message box

查看:23
本文介绍了GeckoWebBrowser 访问错误的 URL,总是弹出消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

www.addssds333fdsd.com.cn could not be found. Please check the name and try again.

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

当我访问一个错误的 URL 时,应用程序会弹出消息框.

When I Access An incorrect URL,Application will pop up message box.

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

How to catch the Exception or drop the message box.

推荐答案

您需要实现 nsIPromptServcice2 和 nsIPrompt 接口

You need to implement the nsIPromptServcice2 and nsIPrompt interfaces

在那里您将获得一个方法列表(例如 Alert();),您只需在其中不提供实现即可.这将捕获"异常.

There you will get a list of methods (e.g. Alert();) where you simply don't provide an implementation. That will 'catch' the exception.

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

Create a following class (you will need to provide implementation for a bunch of methods, such as Alert, Confirm, Prompt etc

public class FilteredPromptService : nsIPromptService2, nsIPrompt
{

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

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

Then, somewhere at the startup of the browser app (maybe in Application_Startup() in case of WPF), assign the prompt service:

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

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

Also, please notice that the above PromptService is static, so this will be applied to all instances of GeckoBrowser in your application.

这篇关于GeckoWebBrowser 访问错误的 URL,总是弹出消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆