I have a URL link which I am displaying in WebView.
Now, when this page loads I need to remove certain elements/ blocks from this web page so that only a certain part is present.
I am using javascript inside onPageFinished method for this. here is how I am doing it :
mWebView.loadUrl("javascript:document.getElementById('main_nav').style.display=\"none\";");
this works fine, but for some divs, id is not present instead of that we have just class eg.-
<div class="left_rail">
Now, i have to remove this div, but I don’t know how to do it.
I tried this –
mWebView.loadUrl("javascript:document.getElementById('main').getElementsByClassName('left_rail').style.display=\"none\";");
But this did not work.
getElementsByClassNamereturns a list of elements. The first of which can be obtained this way:Use a loop to get rid of all of them.