Android Question Catch URL from ad displayed on webview

Sifu

Active Member
Hello,
I'm playing a bit with ads. So I'm using an JS script from an ad agency on my website and it works very good.
I've made a test B4A project and it I'm loading a separate html file from my server (perhaps the html file could also be in the assets folder) into the webview, the ad is displayed perfectly. I want to display the ad like a kind of banner in my app, not on a separate activity so it does not disturb the user too much.
Normally if a user clicks on the ad, it will open another tab on a browser. If you right click (on PC) you can get the URL, which changes of course per ad.

I know how to open the browser with an URL via for example: StartActivity(p.OpenBrowser(Main.thisweb))

Is it possible to catch the URL in the webview, so that if a user might (long)click the ad it will open a browser externally on the Android phone, and not in the webview itself?

Thanks for any hints!

Regards.
 

Ivica Golubovic

Active Member
Licensed User
Hello,
I'm playing a bit with ads. So I'm using an JS script from an ad agency on my website and it works very good.
I've made a test B4A project and it I'm loading a separate html file from my server (perhaps the html file could also be in the assets folder) into the webview, the ad is displayed perfectly. I want to display the ad like a kind of banner in my app, not on a separate activity so it does not disturb the user too much.
Normally if a user clicks on the ad, it will open another tab on a browser. If you right click (on PC) you can get the URL, which changes of course per ad.

I know how to open the browser with an URL via for example: StartActivity(p.OpenBrowser(Main.thisweb))

Is it possible to catch the URL in the webview, so that if a user might (long)click the ad it will open a browser externally on the Android phone, and not in the webview itself?

Thanks for any hints!

Regards.
Did you try to capture the URL via the OverrideURL event when you click on ad? You can disable page opening by returning True through this event.
 
Upvote 0

Sifu

Active Member
I've found OverrideURL in the Basic Language Guide and an example in SQLite Database guides. And an example here https://www.b4x.com/android/forum/threads/solved-webview-overrideurl-resumable.133413/
I'm now using the example partly from the SQLite DB guide, which seems to do the job, by catching the URL it already is not opening the referal in the webview, so that's good.
You can disable page opening by returning True through this event.
It seems already be doing that, but can you explain how to do that what you mean?

Thanks for pointing me to overrideURL.
 
Upvote 0
Top