在webview android上显示网页的一部分 [英] Display a part of the webpage on the webview android

查看:49
本文介绍了在webview android上显示网页的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个将网页内容加载到 webview 的应用程序.我想在整个 webview 中只显示一个特定的东西,而不是网页的全部内容.

I want to make an app which loads the content from the webpage into webview. I want to show only a particular thing in the entire webview, not the whole content of the webpage.

这是一个例子.如果我使用: http://us.m.yahoo.com/w/sea​​rch%3B_ylt=A2KL8xs0vUBQMg0AwAkp89w4?submit=oneSearch&.intl=us&.lang=en&.tsrc=yahoo&.sep=fp&p=digital+cameras&x=0&y=0 作为webview的URL,它将页面的所有内容加载到webview上.但我想删除页面的横幅并将其显示在我的应用程序的 webview 上.

Here is an example. If I use: http://us.m.yahoo.com/w/search%3B_ylt=A2KL8xs0vUBQMg0AwAkp89w4?submit=oneSearch&.intl=us&.lang=en&.tsrc=yahoo&.sep=fp&p=digital+cameras&x=0&y=0 as the URL for the webview, it loads all the contents of the page on the webview. But I want to remove the banner of the page and show it on the webview of my application.

我曾尝试通过 CSS 标签使用 adblocker,但这对我没有帮助.请给我一些克服这个问题的想法.

I have tried using adblocker using CSS tags, but that is not helping me. Please give me some idea for overcoming this problem.

谢谢.

推荐答案

感谢您的回答 Zyber.我已经通过在 android 中的 WebView 代码中注入 JavaScript 解决了这个问题.

Thank You for the answer Zyber. I have solved it using injection of JavaScript in the code for WebView in android.

final WebView webview = (WebView)findViewById(R.id.browser);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
 @Override
public void onPageFinished(WebView view, String url)
{
    webview.loadUrl("javascript:(function() { " +
            "document.getElementsByTagName('header')[0].style.display="none"; " +
            "})()");
}
});
webview.loadUrl("http://code.google.com/android");

这解决了我的目的,而且很容易使用.

This solved my purpose and it is easy to use to.

这篇关于在webview android上显示网页的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆