How to handle popups in new tab?

1,550 views
Skip to first unread message

Edgaras Kazlauskas

unread,
Jul 29, 2015, 3:29:04 PM7/29/15
to CefSharp
I spent hours trying to figure out how to make it work. I found little info about it but couldnt make it work.
Currently trying on CefSharp.WinForms.Example, it have tabs but they dont do its job.
For example when I run http://www.popuptest.com/ it creates other windows instead of putting those popups in new tabs. So how I should handle them? Getting url and navigating to it from another tab browser isnt solution.

Alex Maitland

unread,
Jul 29, 2015, 6:16:28 PM7/29/15
to CefSharp, edgar...@gmail.com
That's really the only option with the current version.

A new feature was added to `master` recently, it's not been tested in `WinForms` yet, you can basically provide a new ChromiumWebBrowser instance to host the newly created popup
https://github.com/cefsharp/CefSharp/pull/1150

tharibo

unread,
Jul 30, 2015, 3:05:04 AM7/30/15
to CefSharp, edgar...@gmail.com
Did you have a look at ILifeSpanHandler? It allows you to intercept popups

    public class LifeSpanHandler : CefSharp.ILifeSpanHandler
    {
        public virtual bool OnBeforePopup(IWebBrowser browser, string sourceUrl, string targetUrl, ref int x, ref int y, ref int width, ref int height)
        {
            // Preserve new windows from being opened
            return true;
        }

        public virtual void OnBeforeClose(IWebBrowser browser)
        {
            // DO NOTHING
        }
    }


You can just add a new instance of this class to your ChromiumWebBrowser's LifeSpanHandler property.

Vorici Elveon

unread,
Jul 30, 2015, 1:27:40 PM7/30/15
to CefSharp, edgar...@gmail.com
Hello, I try to implement tharibos suggested class but I get error 'Error    2    'CefSharp.WinForms.LifeSpanHandler' does not implement interface member 'CefSharp.ILifeSpanHandler.OnBeforePopup(CefSharp.IWebBrowser, CefSharp.IFrame, string, ref int, ref int, ref int, ref int, ref CefSharp.IWebBrowser)'    C:\Users\\Desktop\CefSharp-8213471364f91fc1008e7a5570c0fb7210a6e000\CefSharp.WinForms\ChromiumWebBrowser.cs    519    18    CefSharp.WinForms"

Alex Maitland

unread,
Jul 30, 2015, 6:27:09 PM7/30/15
to CefSharp, edgar...@gmail.com, infomak...@gmail.com
The interface may look different depending on the version your using. You likely can't copy and paste the code exactly.
Reply all
Reply to author
Forward
0 new messages