0

This question has been asked and answered before, however I am unable to implement any of the answers - probably due to my complete lack of javascript knowledge.

I'm trying to load a page in a WebView called appWebView. It is an app page on the google play store.

I want to hide the 'install' and 'add to wishlist' buttons of the app and this is the setWebView method I use (Javascript copy pasted from Any way to hide elements from webview? (android)):

public void setWebView(){
    final WebView appWebView = (WebView) findViewById(R.id.appWebView);
    appWebView.getSettings().getJavaScriptEnabled();
    appWebView.getSettings().setJavaScriptEnabled(true);
    appWebView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url) {
            appWebView.loadUrl("javascript:(function() { " + "document.getElementsByClassName" + "('details-actions-right')[0].style" + ".display='none'; })()");
        }
    });
    appWebView.loadUrl(url);
} 

However the page loads as normal in the webview

On the app page, inspecting the element I want to hide shows me:

<div class="details-actions-right"> 

But I cannot hide anything

Obviously, I'm screwing up somehow, but don't know how. I've spent literally all day on this.

Ignacio Ara
  • 2,476
  • 2
  • 26
  • 37
Heinz
  • 75
  • 1
  • 9
  • I'm not sure if it can be done by invoking javascript function(s) using listeners. Even if it does, user can disable JavaScript. I'd direct you to the jsoup project - https://jsoup.org . It does exactly what you're looking for (manipulates retrieved web page elements) – nstosic Oct 13 '16 at 13:46
  • Will I then be able to display the webpage? – Heinz Oct 13 '16 at 14:05
  • Yes, you load the page with `Document doc = Jsoup.connect("").get();` and then manipulate it with other methods. Afterwards, refer to this question on how to display it http://stackoverflow.com/questions/32074071/load-document-to-webview-with-jsoup – nstosic Oct 13 '16 at 14:08

0 Answers0