Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to hide elements from webview? (android)

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.

Thanks

like image 488
ajent Avatar asked Jun 12 '10 20:06

ajent


People also ask

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

How do I hide WebView?

How do I close WebView on Android? Add a close button and on its click set: webview. setVisibility(View. INVISIBLE); webview.

Is Android WebView deprecated?

The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.


1 Answers

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);
like image 162
Linh Avatar answered Sep 18 '22 16:09

Linh