Page 1 of 1

OnBeforeNavigate2 replacement

Posted: Fri Sep 04, 2020 6:26 am
by egold2005
Hello,

What would be the best event for replacing TWebBrowser.OnBeforeNavigate2, i need to examine the URL, perform certain actions and cancel the processing when they click on a link.

Thanks,
Eugene.

Re: OnBeforeNavigate2 replacement

Posted: Fri Sep 04, 2020 8:51 am
by Student
Event OnBeforeBrowse, example

Code: Select all

if request.Url='https://www.google.com/' then
    Result := true;

Re: OnBeforeNavigate2 replacement

Posted: Fri Sep 04, 2020 8:54 am
by egold2005
Thank you.

Re: OnBeforeNavigate2 replacement

Posted: Fri Sep 04, 2020 9:24 am
by egold2005
1. Are there other events to use in the same scenario, because this one does not work well with my existing code.

2. Where can i read the documentation on this event?

Re: OnBeforeNavigate2 replacement

Posted: Fri Sep 04, 2020 1:15 pm
by salvadordf
egold2005 wrote: Fri Sep 04, 2020 9:24 am 1. Are there other events to use in the same scenario, because this one does not work well with my existing code.
TChromium.OnBeforeResourceLoad is similar but TChromium.OnBeforeBrowse is the closest event to TWebBrowser.OnBeforeNavigate2
egold2005 wrote: Fri Sep 04, 2020 9:24 am 2. Where can i read the documentation on this event?
There are several ways to do that. Open the TChromiumCore source code in uCEFChromiumCore.pas and take a look at the events. You will see that they are grouped and each group has a comment with the name of an interface. For example, TChromiumCore.OnBeforeBrowse has ICefRequestHandler and TChromiumCore.OnBeforeResourceLoad has ICefResourceRequestHandler.

Open this page and scroll down a few paragraphs :
https://www.briskbard.com/index.php?lan ... =cef#usage

You will see a bunch of blue links with the name of the CEF classes bellow the text "As you can see in the source code, TChromium has the functions, procedures and events of"

Those classes have the same name as the previous interfaces but without the initial "I".

Click on the "CefRequestHandler" link to see the documentation for TChromiumCore.OnBeforeBrowse :
https://magpcss.org/ceforum/apidocs3/pr ... ndler.html

And click on the "CefResourceRequestHandler" link for more information about TChromiumCore.OnBeforeResourceLoad :
https://magpcss.org/ceforum/apidocs3/pr ... ndler.html

All the CEF documentation is here :
https://magpcss.org/ceforum/apidocs3/

It's a copy of the CEF code comments but the previous link is easier to navigate.