0

I am loading html data into webview using loadDataWithBaseUrl() method. My html includes a JS file with absolute path (file:///android_asset/myjs.js). Now if I set the base url as "file:///android_asset/" or "fake://not_needed" in loadDataWithBaseUrl method, Javascript sometimes does not loads. It works most of the time and I can see the rendered html in webview. But sometimes it fails to execute the Javascript included in the html. I have a viewpager with webview in each page. All webviews are being loaded at the same time.

1 Answer 1

1

Try this :

webView.getSettings().setJavaScriptEnabled(true);

And before making the call to loadUrl :

webView.clearCache(true);
webView.clearHistory();
Sign up to request clarification or add additional context in comments.

3 Comments

I am doing this. Otherwise how will I be able to execute JS. As I said, it works most of the time. The problem happens randomly and on some phones.
Have you tried clearing the cache and the history of the webview? I got my javascript to start loading again, if I called those two right before I call the loadUrl.
Thanks you very much. This works perfectly the way i want. Mixing web technology with native technology will help a lot and save efforts.

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.