问题描述
我想知道是否有可能显示一个网站的某些部分在一个web视图。例如,我有这个网站,以下HTML:
< HTML>
<身体GT;
&所述;股利的id =1> ID 1所述; / ID>
&所述;股利的id =2>标识2'; / ID>
< DIV ID =3> ID第3版; / ID>
< /身体GT;
< / HTML>
,可以在web视图,只显示,例如,该id为3的div内容?我的code是WebWiew:
WebViewClient Web客户端=新WebViewClient(){
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
view.loadUrl(URL);
返回true;
}
};
的WebView myWebView =(web视图)findViewById(R.id.webView1);
myWebView.getSettings()setJavaScriptEnabled(真)。
。myWebView.getSettings()setBuiltInZoomControls(真正的);
。myWebView.getSettings()setBuiltInZoomControls(真正的);
myWebView.setWebViewClient(Web客户端);
myWebView.loadUrl(https://www.example.com);
您可以通过扩展WebViewClient和注入一些JavaScript,这将使得您的网页这样做
公共类MyWebClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
view.loadUrl(URL);
返回true;
}
@覆盖
公共无效onPageFinished(web视图查看,字符串URL){
view.loadUrl(JavaScript的:你的javascript);
}
}
.........
最后MyWebClient myWebViewClient =新MyWebClient();
mWebView.setWebViewClient(myWebViewClient);
有关隐藏元素使用 view.loadUrl(JavaScript的:的document.getElementById(id)的.style.display ='无')
更多信息In Android的web视图,我能够修改网页的DOM?
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:
<html>
<body>
<div id="1">ID 1</id>
<div id="2">ID 2</id>
<div id="3">ID 3</id>
</body>
</html>
it is possible to display in WebView only, for example, the contents of the div with id="3"?My code is WebWiew:
WebViewClient WebClient = new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
};
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setWebViewClient(WebClient);
myWebView.loadUrl("https://www.example.com");
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?
这篇关于机器人的WebView:网站显示只有一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!