有一个我用webview上传的网页,但是我想在顶部隐藏1个文本链接.有没有办法做到这一点?链接在体内,所以我不能整体隐藏身体元素.网页是全部文本,底部是一个小图像,但每次加载时都会生成文本,所以我不能只复制/粘贴正文.
谢谢
小智 22
final WebView webview = (WebView)findViewById(R.id.browser);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
// hide element by class name
webview.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('your_class_name')[0].style.display='none'; })()");
// hide element by id
webview.loadUrl("javascript:(function() { " +
"document.getElementById('your_id').style.display='none';})()");
}
});
webview.loadUrl(url);
Run Code Online (Sandbox Code Playgroud)
我知道了!通过注入javascript我必须使用
webview.loadUrl("javascript:(function(){"+"document.getElementsByTagName('a')[0] .style.display ='none';"+"})()");
这删除了链接(代码).用('img')替换('a')将删除图像.
(感谢lexanderA - 将JavaScript注入WebView)
| 归档时间: |
|
| 查看次数: |
13090 次 |
| 最近记录: |