有什么办法可以从 webview 中隐藏元素?(安卓) [英] Any way to hide elements from webview? (android)

查看:15
本文介绍了有什么办法可以从 webview 中隐藏元素?(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 webview 拉出了一个网页,但是我想隐藏顶部的 1 个文本链接.有没有办法做到这一点?链接在正文中,所以我不能完全隐藏正文元素.网页全是文字,底部只有一个小图片,但是每次加载都会生成文字,所以我不能只是复制/粘贴正文.

There's a webpage I pull up with webview, however i'd like to hide the 1 text link at the top. Is there a way to do this? The link is in the body, so I can't hide the body element in whole. The webpage is all text, and one tiny image at the bottom, but the text is generated each time you load it, so I can't just copy/paste the body.

谢谢

推荐答案

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);

这篇关于有什么办法可以从 webview 中隐藏元素?(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆