Answer the question
In order to leave comments, you need to log in
How to use javascript:(function()) in a WebView or how to display a single element of a web page?
Here I want to discuss a well-known method for hiding elements of a web page viewed in a WebView. The working version is
webview.setWebViewClient(new WebViewClient(){
@Override
public void onLoadResource(WebView view, String url) {
view.loadUrl("javascript:(function() {" +
"document.getElementsByClassName('nameclass')[0].style.display='none';" + "})()");
}
});
Answer the question
In order to leave comments, you need to log in
No, because the display of elements is inherited in a tree-like system of elements, without the ability to easily change the order (especially if you need 'everything to work as it should' universally).
p.s. javascript in the browser is very fast and 99.999% of the brakes are dom manipulations i.e. the code for finding all the necessary elements on the page will spend a matter of milliseconds of time, and then almost a second hiding them, and this most likely cannot be accelerated in any way.
pps if you still need to speed up, first try modifications that do not change the dimensional structure of the document (so that the elements do not change their size and the position of others when hiding their content)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question