无法找到 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/