我有一个网站 - > https://docs.google.com/viewer?url=http://pzstiz.swiebodzin.pl/zastepstwa/PZSTiZ_zastepstwa.pdf
在我的应用程序中使用webView。 我想加载一个specefic div(图片来自这个pdf)
<div class="ndfHFb-c4YZDc-cYSp0e-DARUcf-PLDbbf ndfHFb-c4YZDc-AHmuwe-wcotoc-zTETae"></div>
有我的代码:
package musial.pzstis.com.pzstiz;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class Main2Activity extends Activity {
WebView myWebView3;
ProgressBar progressBar3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
myWebView3 = (WebView) findViewById(R.id.webView);
progressBar3 = (ProgressBar) findViewById(R.id.progressBar7);
myWebView3.setWebViewClient(new myWebClient());
myWebView3.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = myWebView3.getSettings();
myWebView3.loadUrl("https://docs.google.com/viewer?url=http://pzstiz.swiebodzin.pl/zastepstwa/PZSTiZ_zastepstwa.pdf");
webSettings.setBuiltInZoomControls(true);
myWebView3.setInitialScale(285);
myWebView3.getSettings().setUseWideViewPort(true);
myWebView3.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
myWebView3.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
}
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
progressBar3.setVisibility(View.VISIBLE);
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progressBar3.setVisibility(View.GONE);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView3.canGoBack()) {
myWebView3.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
答案 0 :(得分:0)
您可以webview
加载javascript code
。
var all = document.getElementsByTagName(“*”);
for (var i=0, max=all.length; i < max; i++) {
// Do something with the element here
// In your condition,you can do like this:
if(all[i].classname != 'ndfHFb-c4YZDc-cYSp0e-DARUcf-PLDbbf ndfHFb-c4YZDc-AHmuwe-wcotoc-zTETae')
all[i].style.display='none';
}
String s = "xxxx"// copy above code
webView.load(s);