Cef Sharp没有显示使用window.open调用的弹出窗口

时间:2016-02-24 12:47:35

标签: javascript c#-4.0 popupwindow cefsharp

我使用CefSharp.WinForms构建了一个应用程序。一切都很好,但当任何网站使用javascript window.open()显示弹出窗口时,它将无法正常工作。 我已经实现了ILifeSpanHandler,它对链接工作得非常好,但在使用window.open()时失败了。任何人都可以帮助我处理window.open()

EDIT-1 LifeSpanHandler实施

public class LifeSpanHandler : ILifeSpanHandler
{
    public bool DoClose(IWebBrowser browserControl, IBrowser browser)
    {
        return false;
    }

    public void OnAfterCreated(IWebBrowser browserControl, IBrowser browser)
    {
        //throw new NotImplementedException();
    }

    public void OnBeforeClose(IWebBrowser browserControl, IBrowser browser)
    {
        //throw new NotImplementedException();
    }

    public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
    {
        var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

        ChromiumWebBrowser chromiumBrowser = null;

        var windowX = windowInfo.X;
        var windowY = windowInfo.Y;
        var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
        var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

        chromiumWebBrowser.Invoke(new Action(() =>
        {
            var owner = chromiumWebBrowser.FindForm();
            chromiumBrowser = new ChromiumWebBrowser(targetUrl)
            {
                LifeSpanHandler = this
            };
            chromiumBrowser.SetAsPopup();

            var popup = new Form
            {
                Left = windowX,
                Top = windowY,
                Width = windowWidth,
                Height = windowHeight,
                Text = targetFrameName
            };

            owner.AddOwnedForm(popup);

            //popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" });
            popup.Controls.Add(chromiumBrowser);

            popup.Show();
        }));

        newBrowser = chromiumBrowser;

        return false;
    }
}

0 个答案:

没有答案