GeckoWebBrowser access an incorrect URL,Always pop up message box

隐身守侯 提交于 2019-12-01 20:41:46

问题


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");

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

How to catch the Exception or drop the message box.


回答1:


You need to implement the nsIPromptServcice2 and nsIPrompt interfaces

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

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
}

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();

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



来源:https://stackoverflow.com/questions/40737542/geckowebbrowser-access-an-incorrect-url-always-pop-up-message-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!