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
Try this :
webView.getSettings().setJavaScriptEnabled(true);
And before making the call to loadUrl :
webView.clearCache(true);
webView.clearHistory();
3 Comments
Vivek
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.
Ronish
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.
Ahesanali Suthar
Thanks you very much. This works perfectly the way i want. Mixing web technology with native technology will help a lot and save efforts.