Good day.
Interested in whether it is possible, so to speak, in real-time to enable / disable js execution through a webview. Because If you disable js initially, it does not load the page you need, just a blank sheet, and if you turn it on, it will load it, but after I click on the site "next", the next page will be loaded, on which I already need to disable js.
The question is: is it possible to dynamically disable / enable js or is it possible to perform only certain js? Thank.

    1 answer 1

    Inherit the class from WebView and override the onPageFinished method like this:

    @Override public void onPageFinished(WebView webView, String url) { if (url.contains("АДРЕС_НУЖНОЙ_СТРАНИЦЫ")) { webView.getSettings().setJavaScriptEnabled(false); } super.onPageFinished(view, url); } 
    • Those. It turns out that I have to reload the page? Or will they turn off before the page loads? - Mhl Chm
    • They will turn off after the page loads. Instead of ADDRESS_NEW_STARTING - insert the address of the page on which you want to disable JS. Well, or! Url.contains ..., if for all but a certain - Ruslan Mukhametshin
    • Is it possible to simply take and without loading the site, execute certain scripts from it? Well, let's say these are fixed js, but not everything is needed, it is possible to simply take and register which scripts need to be executed and that's all? And those that are not necessary, respectively, do not prescribe and do not perform. Roughly speaking, filter out - Mhl Chm