【发布时间】:2014-02-26 18:06:31
【问题描述】:
我正在使用 web.loadUrl(url); 将 url 加载到 webview 中。现在我想在 url 完成加载后删除部分正文内容。
来自url的数据如下:
<html>
<body>
<div class="header" data-role="header" data-theme="a">
<a data-icon="back" class="header-icon" data-iconpos="notext" href="mymob-web-mobile/restricted/menu.xhtml" data-ajax="false"> <span>Back</span> </a>
<!--Title-->
<h1>???help.main.title???</h1>
</div>
<div id="well">Hello World</div>
<body>
</html>
我想去掉url中的这部分
<div class="header" data-role="header" data-theme="a">
<a data-icon="back" class="header-icon" data-iconpos="notext" href="mymob-web-mobile/restricted/menu.xhtml" data-ajax="false"> <span>Back</span> </a>
<!--Title-->
<h1>???help.main.title???</h1>
</div>
经过一些研究,我得出了这个解决方案:
web= (WebView)findViewById(R.id.web);
web.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
web.loadUrl("javascript:var con = document.getElementByTagName('<div class=\"header\" data-role=\"header\" data-theme=\"a\"> '); " +
"con.style.display = 'none'; ");
}
});
web.clearCache(true);
web.clearHistory();
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.loadUrl(Constant.URL_AIDE, headers);
但是 div 元素并没有被删除。
一个summery是,要删除的div
<div class="header" data-role="header" data-theme="a">
<a data-icon="back" class="header-icon" data-iconpos="notext" href="mymob-web-mobile/restricted/menu.xhtml" data-ajax="false"> <span>Back</span> </a>
<!--Title-->
<h1>???help.main.title???</h1>
</div>
预期结果
<html>
<body>
<div id="well">Hello World</div>
<body>
</html>
有什么建议
【问题讨论】:
-
创建css文件并放入assets文件夹并通过应用css文件路径加载url
-
@BirajZalavadia 你怎么能做到这一点?
标签: android webview android-webview