2

I'm working on an Android application in which I pre-load a URL to a WebView (simply with webview.loadUrl("www.google.com")). Then, at some later point, I display the WebView by adding it to a visible view. I do this so that the WebView isn't fetching information when it's being shown. it already has the website downloaded.

The problem with this is, if I load up a website that contains JavaScript, the JavaScript runs immediately (in the background) when the WebView finishes loading instead of once the WebView is shown.

I would rather the WebView just download the website, then, once it is shown, begin running the scripts contained. Any idea on how to do this?

1 Answer 1

3

Haven't tried this yet but the docs say that you can disable JavaScript execution in a WebView using WebSettings setJavaScriptEnabled() method:

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(false);

You could toggle this flag when you are loading and displaying the WebView.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.