I am developing a web view app for my company website. In the articles pages, we have links to related products. For example site.com/product/product
name. How can I disable all the link that starts with site.com/product/
? I have searched here and other websites but I could not find a solution.
private class mWebViewClient extends WebViewClient {
/* @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
}*/
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadResource(WebView view, String url) {
view.loadUrl("javascript:var footer = document.getElementById(\"footer\"); footer.parentNode.removeChild(footer); var header = document.getElementById(\"header_main\"); header.parentNode.removeChild(header); var bread = document.getElementsByClassName('breadcrumb breadcrumbs avia-breadcrumbs')[0].style.display='none'");
}
}
Implement the method shouldOverrideUrlLoading()
as following:
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if(request.getUrl().toString().contains("site.com/product/")) {
return true;
}
else {
return super.shouldOverrideUrlLoading(view, request);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.