[SOLVED] Cef OnBeforePopup doesn't fire when targetname same

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.

Re: Cef OnBeforePopup doesn't fire when targetname same

Postby HarmlessDave » Mon Apr 24, 2017 12:25 pm

In OnBeforePopup you could detect that it is the form, and do either of these:
- block the navigation, then execute JavaScript to open the new window with a custom name like I showed you, so the parent - child relationship is preserved
- allow the navigation, but then execute JavaScript to re-write the page HTML so that you change the target name to FORM_2, FORM_3, ... for the next time a user clicks it.

Both of those only add a performance penalty at the time the user clicks to open a new window.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Cef OnBeforePopup doesn't fire when targetname same

Postby salihcantekin » Fri Apr 28, 2017 4:29 am

Thanks a lot.
I could manage this with the following code block on top of the OnBeforePopup.

The next question is the parameters in the "window.open". (scroolbars, menubars etc.) can i get them with some way ? if i couldn't i will prepare them with the "popupFeatures" and "windowInfo" properties.


var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;
if (targetFrameName.Equals("REPORT"))
{
targetFrameName = String.Format("{0}_{1}", targetFrameName, DateTime.Now.ToString("HHmmss"));
chromiumWebBrowser.ExecuteScriptAsync($"window.open('{targetUrl}','{targetFrameName}','scrollbars=YES,menubar=NO,resizable=yes,width=800,height=600,top=20,left=20');");
return true;
}
salihcantekin
Newbie
 
Posts: 8
Joined: Mon Apr 17, 2017 3:17 am

Re: Cef OnBeforePopup doesn't fire when targetname same

Postby HarmlessDave » Sun Apr 30, 2017 5:29 pm

The next question is the parameters in the "window.open". (scroolbars, menubars etc.) can i get them with some way ?


Do you mean the parameters coming from the page, in the request that you blocked and replaced? Did you look up the CefPopupFeatures object?
Code: Select all
http://magpcss.org/ceforum/apidocs/projects/(default)/CefLifeSpanHandler.html#OnBeforePopup(CefRefPtr<CefBrowser>,constCefPopupFeatures&,CefWindowInfo&,constCefString&,CefRefPtr<CefClient>&,CefBrowserSettings&)
http://magpcss.org/ceforum/apidocs/projects/(default)/cef_types_wrappers.h.html - struct CefPopupFeaturesTraits


It is also possible to "screen scrape" the source code of the page if you use frame->GetSource.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Cef OnBeforePopup doesn't fire when targetname same

Postby salihcantekin » Wed May 03, 2017 1:27 am

I've tried this and it works. :)

Thanks for helping :)

private String getValueForJs(bool Value)
{
return Value ? "YES" : "NO";
}


if (targetFrameName.Equals("REPORT"))
{
targetFrameName = String.Format("{0}_{1}", targetFrameName, DateTime.Now.ToString("HHmmss"));
String scriptStr = "window.open('{0}','{1}','scrollbars={2},menubar={3},resizable={4},width={5},height={6},top={7},left={8}')";

scriptStr = String.Format
(
scriptStr,
targetUrl,
targetFrameName,
getValueForJs(popupFeatures.ScrollbarsVisible),
getValueForJs(popupFeatures.MenuBarVisible),
getValueForJs(popupFeatures.Resizable),
popupFeatures.Width,
popupFeatures.Height,
popupFeatures.Y,
popupFeatures.X
);

chromiumWebBrowser.ExecuteScriptAsync(scriptStr);
return true;
}
salihcantekin
Newbie
 
Posts: 8
Joined: Mon Apr 17, 2017 3:17 am

Previous

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 46 guests