Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow new window/tab #600

Closed
richmondwang opened this issue Nov 13, 2014 · 6 comments
Closed

Disallow new window/tab #600

richmondwang opened this issue Nov 13, 2014 · 6 comments

Comments

@richmondwang
Copy link

Hi, I was looking anywhere and tried anything I can but I cant seem to disable or disallow creating new window (or tab).
Like when I click the middle mouse button, or shift+Enter on forms, etc..
I like to disallow that, because my app should only have one IWebBrowser view.

CefSharp is great! I'm loving it ^_^

@dviz
Copy link

dviz commented Nov 13, 2014

You can try implementing ILifeSpanHandler and reload pending url into current browser instance

    public virtual bool OnBeforePopup(IWebBrowser browser, string url, ref int x, ref int y, ref int width, ref int height)
    {
        // Preserve new windows to be opened and load all popup urls in the same browser view
        browser.Load(url);
        //
        return true;
    }

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

@richmondwang
Copy link
Author

Thanks! @dviz

@jornh
Copy link
Contributor

jornh commented Nov 13, 2014

😄👍 Thanks @dviz!
I've invented a new issue label and #600 is the first one we put that one onto ...

@amaitland
Copy link
Member

The OnBeforePopup method may have changed, the basic concept should still be the same.

@lavkeshdwivedi
Copy link

Hi Alex,

public virtual bool OnBeforePopup(IWebBrowser browser, string url, ref int x, ref int y, ref int width, ref int height)
{
// Preserve new windows to be opened and load all popup urls in the same browser view
browser.Load(url);
//
return true;
}

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

this solution is not working in version 57

@judge2020
Copy link

judge2020 commented Nov 18, 2017

New one that works with the current stable nuget release 57

    public class BrowserLifeSpanHandler : ILifeSpanHandler
    {
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName,
            WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo,
            IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;
            return true;
        }

        public void OnAfterCreated(IWebBrowser browserControl, IBrowser browser)
        {
            //
        }

        public bool DoClose(IWebBrowser browserControl, IBrowser browser)
        {
            return false;
        }

        public void OnBeforeClose(IWebBrowser browserControl, IBrowser browser)
        {
            //nothing
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants