title: Hiding an element in WebView in Android as it is loaded (or preventing it from loading altogether)
body: <p>I am loading a URL in a WebView in Android, and I want to hide an element that appears near the top of a very long page. Now, I am currently using javascript to hide the element in the onPagefinished method as below:</p>
  
  <pre><code>public void onPageFinished(WebView view, String url) {
                  super.onPageFinished(view, url);
  
                  mWebView.loadUrl("javascript:(function() { " +
                          "document.getElementsByClassName('to-hide')[0].style.display='none';})()");
  }
  </code></pre>
  
  <p>However, this element is near the top of a page, and my page is fairly long, so this code doesn't execute till maybe 10 seconds in. Now I need to be able to hide this element as soon as it appears, or preferably block it from being loaded altogether, because having it visible causes serious interface issues.</p>
  
  <p>Any idea how can I do this? </p>
  
  <p>(BTW putting the same code in onPageStarted doesn't seem to work since I believe the element is not loaded at that point).</p>