Disable GeckoFX confirm messages

2019-05-23 23:53发布

问题:

I am using Gecko Web browser version 21.0.1 and .net Framework 4.0 in my windows application.

When I navigate to certain web pages I get Pop up confirm message:

This web page is being redirected to a new location. Would you like to resend the form data you have typed to the new location?

How can I disable this kind of messages?

So far I have tried the following settings, but they didn't help:

GeckoPreferences.User["security.warn_viewing_mixed"] = false;
GeckoPreferences.User["plugin.state.flash"] = 0;
GeckoPreferences.User["browser.cache.disk.enable"] = false;
GeckoPreferences.User["browser.cache.memory.enable"] = false;

回答1:

You could try providing you own nsIPromptService2 / nsIPrompt implementation.

Run this early on program start up (Although after XPCom.Initalize)

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

Where FilteredPromptService is defined something like this:

internal class FilteredPromptService : nsIPromptService2, nsIPrompt
{
    private static PromptService _promptService = new PromptService();

    public void Alert(nsIDOMWindow aParent, string aDialogTitle, string aText)
    {
        if(/*want default behaviour */)
        {
         _promptService.Alert(aDialogTitle, aText);
        }
        // Else do nothing 
    }

    // TODO: implement other methods in similar fashion. (returning appropriate return values)
}

You will also need to make sure that error pages are not enabled:

GeckoPreferences.User["browser.xul.error_pages.enabled"] = false;