I want to remove the "header" element from a webpage with the help of this answer Display a part of the webpage on the webview android
But I am getting an error message; see this https://dl.dropboxusercontent.com/u/15065300/Check-2.jpg
Here is my full code:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
webView.loadUrl("javascript:(function() { " +
"document.getElementsByTagName('myDiv1')[0].style.display="none"; " +
"})()");
}
});
webView.loadUrl("http://skyasim.info/abc.html");
}
}
Manifest permission as well
<uses-permission android:name="android.permission.INTERNET" />
You need to escape your "
. See the Escape Sequences section.
webView.loadUrl("javascript:(function() { " +
"document.getElementsByTagName('header')[0].style.display=\"none\"; " +
"})()");
This worked for me:
webView.loadUrl("javascript:var con = document.getElementById('a'); " +
"con.parentNode.removeChild(con); ");
htmlCode:
<ul>
............
<div id="a">
<H4 align="center"> something</H4>
</div>
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With