Any way to hide elements from webview? (android)

前端 未结 3 1996
孤城傲影
孤城傲影 2020-12-09 11:24

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 bod

3条回答
  •  攒了一身酷
    2020-12-09 11:50

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

提交回复
热议问题