如何使用CEFSharp库阻止导航?

时间:2015-08-31 11:53:11

标签: c# cefsharp

我想使用CEFSharp库和WinForms阻止我的应用程序的导航。我没有找到解决方案,这里只有一些链接: How to disable backspace "go back" navigation?但它对我不起作用。 你帮我吗?

- > RequestHandler.cs

class RequestHandler : IRequestHandler
{
    public bool OnBeforeBrowse(IWebBrowser browser, IRequest request, bool isRedirect, bool isMainFrame)
    {
        if ((request.TransitionType & TransitionType.ForwardBack) != 0)
        {
            return true;
        }
        return false;
    }

    public bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl)
    {
        return false;
    }

    public void OnPluginCrashed(IWebBrowser browser, string pluginPath)
    {

    }

    public CefReturnValue OnBeforeResourceLoad(IWebBrowser browser, IRequest request, bool isMainFrame)
    {
        return CefReturnValue.Continue;
    }

    public bool GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme,
        ref string username, ref string password)
    {
        return true;
    }

    public bool OnBeforePluginLoad(IWebBrowser browser, string url, string policyUrl, WebPluginInfo info)
    {
        return true;
    }

    public void OnRenderProcessTerminated(IWebBrowser browser, CefTerminationStatus status)
    {

    }
}

- >在Program.cs中

_browser = new ChromiumWebBrowser(url)
        {
            RequestHandler = new RequestHandler(),
            Dock = DockStyle.Fill,
            RequestHandler = new RequestHandler()
        };

P.S。我在浏览器中启动的应用程序是单页。

0 个答案:

没有答案