Asim Krishna Das Asim Krishna Das - 1 year ago 45
Android Question

Removing a Tag from a webpage on android WebView

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

Here is my full code:

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) {

webView = (WebView) findViewById(;
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url)
webView.loadUrl("javascript:(function() { " +
"document.getElementsByTagName('myDiv1')[0].style.display="none"; " +



Manifest permission as well

<uses-permission android:name="android.permission.INTERNET" />

Answer Source

You need to escape your ". See the Escape Sequences section.

webView.loadUrl("javascript:(function() { " +
    "document.getElementsByTagName('header')[0].style.display=\"none\"; " +