Nabajyoti Das
Nabajyoti Das

Reputation: 524

Remove some part of a webpage in android webview and then display it

I have been able to successfully remove a part of a webpage using the below code, but the only problem is that the webview first display the complete webpage and then it removes the element 'header-text-nav-container' although I am calling it onPageFinished(). I tried many different ways but all in vain. How to display the webpage in the webview only after successfully removing the element 'some-part' in my case 'header-text-nav-container'. Please help

public class myWebClient extends WebViewClient
{
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);

        view.loadUrl("javascript:(function() { " +
                "document.getElementById('header-text-nav-container').style.display='none'; " +
                "})()");

        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        }

    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }


   @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);

    }


}

Upvotes: 2

Views: 1974

Answers (1)

Nabajyoti Das
Nabajyoti Das

Reputation: 524

I finally solved the problem by showing a progress dialog and then dismissing the progress dialog when the 'header' is successfully removed. Thus I solved the problem partially.

Upvotes: 1

Related Questions