c# - 禁用 GeckoFX 确认消息

标签 c# winforms geckofx

我在我的 Windows 应用程序中使用 Gecko Web 浏览器版本 21.0.1 和 .net Framework 4.0。

当我导航到某些网页时,我会弹出确认消息:

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?

如何禁用此类消息?

到目前为止,我已经尝试了以下设置,但它们没有帮助:

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;

最佳答案

您可以尝试提供您自己的 nsIPromptService2/nsIPrompt 实现。

在程序启动时尽早运行(尽管在 XPCom.Initalize 之后)

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

FilteredPromptService 的定义如下:

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)
}

您还需要确保未启用错误页面:

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

关于c# - 禁用 GeckoFX 确认消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896060/

相关文章:

c# - 当不同程序集中的 App.xaml 时,Visual Studio 2012 XAML 设计器不显示正确的内容

wpf - WinForms互操作,从WinForms-> WPF拖放

c# - 为什么不在 ContinueWith 中执行任务?

c# - 判断 SQL Server 是否可用的最快方法

c# - 如何通过 GeckoFX 执行 Javascript 命令

c# - geckofx webbrowser不在Windows窗体c#中播放音频

c# - 如何使用 GeckoFX/C# 获取所有 HTML 属性

c# - 如何创建对现有对象的引用?特别是对于 Get-Service 对象之一?

c# - Azure.Data.Tables通用基类问题

c# - 在 Visual Studio 中使用来自 SQL Server 的数据库