Cefsharp: How to disable open page in new window?

Created on 14 Dec 2014  ·  3Comments  ·  Source: cefsharp/CefSharp

How to disable open page in new window? I want to open a new page in self

duplicate

Most helpful comment

As the api has changed since the last answer has been posted, here's how to acheive that

Implement ILifeSpanHandler in a new class.

With the following implementation of OnBeforePopup

public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            browser.MainFrame.LoadUrl(targetUrl);
            newBrowser = null;
            return true;
        }

Then instantiate your implementation and set the LifeSpanHandler property of your browser with it.

All 3 comments

Closing as this is a duplicate. See #600

As the api has changed since the last answer has been posted, here's how to acheive that

Implement ILifeSpanHandler in a new class.

With the following implementation of OnBeforePopup

public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            browser.MainFrame.LoadUrl(targetUrl);
            newBrowser = null;
            return true;
        }

Then instantiate your implementation and set the LifeSpanHandler property of your browser with it.

Was this page helpful?
0 / 5 - 0 ratings