gpt4 book ai didi

android - 有什么方法可以从 webview 中隐藏元素? (安卓)

转载 作者:可可西里 更新时间:2023-11-01 18:43:55 25 4
gpt4 key购买 nike

我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com