在我的Android应用程序中,我有一个WebView,在它显示任何内容之前,我做了它,以便我的网站上的某些元素不会显示javascript.It但是只能在第一次加载时工作,如果你实际导航通过网站(例如点击帖子),它将显示我不想要的所有元素。它之前工作得非常好,现在我无法弄清楚它为什么不起作用。我很感激任何帮助!
mWebView = (WebView) view.findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
return false;
}
@Override
public void onPageStarted(final WebView view, final String url, final Bitmap favicon) {
bar.setVisibility(View.VISIBLE);
mWebView.setVisibility(View.INVISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url)
{
mWebView.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('fa fa-youtube')[0].style.display='none'; " +
"document.getElementsByClassName('fa fa-twitter')[0].style.display='none'; " +
"document.getElementsByClassName('menu-primary-container')[0].style.display='none'; " +
"document.getElementsByClassName('menu-toggle')[0].style.display='none'; " +
"document.getElementsByClassName('widget_slider_area')[0].style.display='none'; " +
"})()");
bar.setVisibility(View.GONE);
mWebView.setVisibility(View.VISIBLE);
super.onPageFinished(view, url);
}
});
mWebView.loadUrl("http://mywebsite.com");