Display a part of the webpage on the webview android

前端 未结 3 641
南笙
南笙 2020-11-29 06:08

I want to make an app which loads the content from the webpage into webview. I want to show only a particular thing in the entire webview, not the whole content of the webpa

3条回答
  •  旧时难觅i
    2020-11-29 06:56

    I got the solution to add this:

    view.getSettings().setJavaScriptEnabled(true);
            view.setWebViewClient(new WebViewClient() {
    
                @Override
                public void onPageFinished(WebView view, String url)
                {
                    view.loadUrl("javascript:(function() { " +
                            "var head = document.getElementsByClassName('header')[0].style.display='none'; " +
                            "var head = document.getElementsByClassName('blog-sidebar')[0].style.display='none'; " +
                            "var head = document.getElementsByClassName('footer-container')[0].style.display='none'; " +
                            "})()");
    
                }
            });
            view.loadUrl("your url");

    Adding (var head =) looks like to hide my class in webview.

    I hope this will be helpful for someone.

提交回复
热议问题