Page 1 of 1

How to intercept and open a given url in a new window

Posted: Wed Apr 05, 2023 10:51 am
by darkducke
I need to check if the browser will navigate to the url ""https://www.example.com" and make it open in another CEFWindowParent that I have in the form maintaining the user session and canceling the current browser navigation, keeping on the same page.

I checked that there are "OnBeforeBrowse" and "OnBeforeResourceLoad" events. My question is, which of these should I use and how to share the user session logged in Browser1 to Browser2

Thanks a lot for any help!

Re: How to intercept and open a given url in a new window

Posted: Wed Apr 05, 2023 1:40 pm
by salvadordf
Hi,

You can use the TChromium.OnBeforeBrowse event and set the "Result" parameter to TRUE to cancel the navigation if request.Url has certain value.

Then save the request.Url value and create a new browser2 in the main application thread that will have request.Url as the TChromium.DefaultUrl property value.

This should work on most cases as long as both browsers share the same cache directory but if the original request had some POST information then you will lose it.

If the user clicked on a link that required a new tab or new window the browser would trigger the TChromium.OnBeforePopup or TChromium.OpenUrlFromTab events. See the TabbedBrowser2 demo for more details about handling these events.