Block all links inside a WebView
To controll what happens when a user clicks on a link inside a WebView you will have to implement your own WebViewClient and override the shouldOverrideUrlLoading() method.
public class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading
(WebView view, String url) {
// here you can check the url
// (whitelist / blacklist)
return true;
// will NOT load the link
// use "return false;" to allow it to load
}
}
Using your new WebViewClient is easy:
webview.setWebViewClient(new CustomWebViewClient());
Written by Dylan Marriott
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Webview
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#