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 ^_^
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
}
Thanks! @dviz
:smile::+1: Thanks @dviz!
I've invented a new issue label and #600 is the first one we put that one onto ...
The OnBeforePopup
method may have changed, the basic concept should still be the same.
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
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
}
}
Most helpful comment
You can try implementing ILifeSpanHandler and reload pending url into current browser instance