Block URL in WebView

cbanks

Active Member
Licensed User
Longtime User
Is there a way to block pages from a certain domain in a WebView? In my app I load a WebView that points to a specific domain. I don't want the ads on that site to appear though. Thanks.
 

cbanks

Active Member
Licensed User
Longtime User
Does anyone know how to block certain web sites in a WebView, but allow other sites to be browsed with basic4android code?
 
Upvote 0

admac231

Active Member
Licensed User
Longtime User
Give it a bit longer than 5 hours. Patience is a virtue.

To answer your question though, use the Override_URL sub to look for the domain(s) you want to block and stop the Webview from loading. This only uses the actual URL to be loaded though, not specific elements (so it won't block ads, only stop the loading of pages from certain domains)

B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If url.IndexOf("google.com") >-1 Then
      Return True
   End If
End Sub

will stop any pages from google.com loading. If, however, you load any random page that has Google AdSense ads it wont stop anything.

It seems rather unethical to want to display a webpage and not the ads - unless that webpage is your own - so I won't be giving an answer for that.
 
Last edited:
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
Sorry, I'll be more patient in the future.

Yes, the web site is mine. I've created an app that basically lets people browse my web site content. I want to create a paid app that lets people browse my site without the ads. So, yes it's my site and I want to know how to block ads for those who have paid for the app.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Does your web site is in Joomla or Wordpress or CSS/HTML?

If it is in Joomla or WordPress then you can make your site mobile native with plugin and there turn off ads. A long ago I was doing something with Joomla
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
If you used PHP/ASP so it will be simple.
 
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
Does anyone know the code to block ads on a page while allowing the page to be displayed? Thanks.
 
Upvote 0
Top