-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Close tab on window.close() #1084
Comments
You can implement |
Hi Alex, thank you for your quick response. I tried to follow the OnBeforeClose approach as the #439 will not work for me. The hosted web applications are not in our hand to be changed. I tried following test application: Having a Window which hosts the CefSharp browser and which also implements ILifeSpanHandler. When triggering the closeWindow() javascript I saw once that the browser was closed but the handler OnBeforeClose was not hit. It seems general an issue to get window.close() working properly in Chrome. But when it closes I don't see the method OnBeforeClose() being called. Did I missed something here? Cheers, public partial class MainWindow : Window, ILifeSpanHandler
{
public const string TestResourceUrl = "http://test/resource/load";
public MainWindow()
{
InitializeComponent();
Cef.Initialize(new CefSettings());
//browser.Address = "http://www.google.de";
var handler = browser.ResourceHandler;
const string responseBody = "<html><head><script type='text/javascript'> function closeWindow(){window.open('', '_self', '');window.close();}</script></head><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p><button onclick='closeWindow()'>Close window</button></body></html>";
handler.RegisterHandler(TestResourceUrl, ResourceHandler.FromString(responseBody));
browser.Address = TestResourceUrl;
}
public void OnBeforeClose(IWebBrowser browser)
{
throw new NotImplementedException();
}
public bool OnBeforePopup(IWebBrowser browser, string url, ref int x, ref int y, ref int width, ref int height)
{
throw new NotImplementedException();
}
} |
It's not enough to implement Based on your code something like
An example of setting the Also your call to (It's also helpful if you include flavor, e.g. |
Also, as they're javascript and html you can pretty much inject anything you like, so you could hook |
Hi Alex, thank you very much for your valuable hints. After assigning the Sorry for the poor information about the version and the flavor. I'm using CefSharp 39 pre03 for my tests. We are working in the repository code with stable version 39 . The UI is WPF based. About the java script injection. You are right, this is also a possibility to get the things working. But my first intension was to get it run with CefSharp mechanism and without altering the hosted pages. Thank you again for you great support! |
Great 👍 |
Hi all,
I have one question concerning handling of window.close() calls from the page hosted in CefSharp browser control.
We have built a tabbed window where we host a CefSharp browser in each tab. We have now the situation that we have web applications hosted in the tabs where the user can trigger a close action in the hosted page which basically calls a window.close() javascript code. In this case we would like to get notified in our C# application (so basically the tab hosting the CefSharp browser) so that we can also close the tab.
Is there a way of doing this with CefSharp?
Thank you in advance and best regards,
Uzay
The text was updated successfully, but these errors were encountered: