我们在利用webview加载网页的过程中,会遇到这样的需求。
网页中的内容并不是我们都需要的 ,我们需要对其中的一些内容进行隐藏,解决办法如下:
网页中的内容并不是我们都需要的 ,我们需要对其中的一些内容进行隐藏,解决办法如下:
final String insertJavaScript = "javascript:window.οnlοad=function(){ " + "document.getElementsByClassName('headtitle')[0].style.display='none'; " + "document.getElementsByClassName('trans')[0].style.display='none';}";mWebView.setWebViewClient(new WebViewClient() {
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStarted(view, url, favicon); view.loadUrl(insertJavaScript); Log.v(TAG, "onPageStarted"); }
}