Intercept browser close event before onbeforeunload

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Intercept browser close event before onbeforeunload

Postby me12 » Tue Nov 18, 2014 11:13 am

Can you override/customise the CefBrowserHost::CloseBrowser(false) method somehow?

What I need is:
To stop the browser close event before the "onbeforeunload" event is triggered.

What I do at the moment is:
Override "CefLifeSpanHandler::DoClose()" and add custom close behaviour but that is too late since "onbeforeunload" has been called already.

Why I need this, is:
Because I am using a hughe framework that does something on the "onbeforeunload" event. And I only want that to happen when I actually close the browser, not when I intercept the close event in CEF3.

Btw: I am using the "cefsimple" client. All that window stuff, event messages, etc. is encapsulated there. And I would like to avoid implementing everything myself now, since this is the last little issue I am encountering.

Thank you already!
me12
Techie
 
Posts: 31
Joined: Thu Jul 10, 2014 12:46 pm

Re: Intercept browser close event before onbeforeunload

Postby magreenblatt » Tue Nov 18, 2014 12:18 pm

What OS and CEF version?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercept browser close event before onbeforeunload

Postby me12 » Tue Nov 18, 2014 5:12 pm

Windows 7 and CEF3 latest stable release.
me12
Techie
 
Posts: 31
Joined: Thu Jul 10, 2014 12:46 pm

Re: Intercept browser close event before onbeforeunload

Postby magreenblatt » Tue Nov 18, 2014 5:30 pm

It would be best to create your own parent window and embed the CEF window as a child as demonstrated by the cefclient application. However, if you need a quick fix you can subclass the WndProc and handle WM_CLOSE yourself. See for example this.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Intercept browser close event before onbeforeunload

Postby me12 » Wed Nov 19, 2014 5:27 am

Awesome! That works wonderfully.

Thank you very much! (once again)
me12
Techie
 
Posts: 31
Joined: Thu Jul 10, 2014 12:46 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 103 guests