Android WebView: display only some part of website

前端 未结 2 1485
心在旅途
心在旅途 2020-12-03 01:30

I wanted to know if it was possible to display only certain parts of a website in a WebView. For example I have this website with the following html:



        
2条回答
  •  星月不相逢
    2020-12-03 02:02

    You can do this by extending WebViewClient and injecting some javascript which will render your web Page

    public class MyWebClient extends WebViewClient {
    
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
    
    @Override
    public void onPageFinished(WebView view, String url) {
        view.loadUrl("javascript:your javascript");
    }
    }
    .........
    final MyWebClient myWebViewClient = new MyWebClient();
    mWebView.setWebViewClient(myWebViewClient);
    

    For hiding elements use view.loadUrl("javascript:document.getElementById(id).style.display = 'none';)

    More info In Android Webview, am I able to modify a webpage's DOM?

提交回复
热议问题