LOUNGE all new asksnapzu ideasforsnapzu newtribes interesting pics videos funny technology science technews gaming health history worldnews business web research entertainment food living internet socialmedia mobile space sports photography nature animals movies culture travel television finance music celebrities gadgets environment usa crime politics law money justice psychology security cars wtf art google books lifetips bigbrother women apple kids recipes whoa military privacy education facebook medicine computing wildlife design war drugs middleeast diet toplists economy fail violence humor africa microsoft parenting dogs canada neuroscience architecture religion advertising infographics sex journalism disaster software aviation relationships energy booze life japan ukraine newmovies nsa cannabis name Name of the tribe humanrights nasa cute weather gifs discoveries cops futurism football earth dataviz pets guns entrepreneurship fitness android extremeweather fashion insects india northamerica
+1
Save

Can anyone give me a hand with Android's WebView?

I'm trying to hide the top banner of a webpage in an Android WebView, but it's doing my head in! I've been at it for days and still can't get it to work.

I have used the code below, to try to disable the displaying of a certain element, the page loads (including the element I don't want) but then disappears completely and shows the word "none".

private class MyWebViewClient extends WebViewClient {

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

    @Override
    public void onPageFinished(WebView webView, String url) {
        webView.loadUrl("javascript:document.getElementsByClassName('welcome')[0].style.display='none';");
    }

}

This is the onCreate

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdView mAdView;
    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    this.webView = (WebView) findViewById(R.id.webview);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // To keep browser in width of phone
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);

    // Sets default zoom
    webView.getSettings().setTextZoom(250);

    //webSettings.setTextZoom(125);

    MyWebViewClient webViewClient = new MyWebViewClient();
    webView.setWebViewClient(webViewClient);

    webView.loadUrl("http://www.example.com");
}

Any class I choose (not just welcome) hides the entire website and displays the word 'none'. And if I change it to try to change height to 0px, it displays '0px' to the screen.

It's not a problem with the specific website I'm using, it does the same for my personal simple HTML / CSS website. Which makes me think either my JavaScript is wrong or there's something in WebView stopping me.

3 years ago by internethermit

Join the Discussion

  • Auto Tier
  • All
  • 1
  • 2
  • 3
Post Comment