我使用 webview 拉出一个网页,但我想隐藏顶部的 1 文本链接。有没有办法做到这一点?链接在正文中,所以我无法隐藏整个正文元素。 该网页全是文本,底部有一张小图片,但每次加载时都会生成文本,所以我不能只复制/粘贴正文。
谢谢
最佳答案
final WebView webview = (WebView)findViewById(R.id.browser);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
// hide element by class name
webview.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('your_class_name')[0].style.display='none'; })()");
// hide element by id
webview.loadUrl("javascript:(function() { " +
"document.getElementById('your_id').style.display='none';})()");
}
});
webview.loadUrl(url);
关于android - 有什么方法可以从 webview 中隐藏元素? (安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3029926/