英文:
Prevent WebView from loading specific URLs
问题
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';");
}
}
英文:
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'");
}
}
答案1
得分: 1
Sure, here's the translated code:
实现以下方法 `shouldOverrideUrlLoading()`:
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().toString().contains("site.com/product/")) {
return true;
} else {
return super.shouldOverrideUrlLoading(view, request);
}
}
英文:
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);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论