JavaScript not working in Android Webview? JavaScript not working in Android Webview? android android

JavaScript not working in Android Webview?


FIXED!Spurred on by the error, I found out that I needed to set

setDomStorageEnabled(true)

for the webview settings.

Thanks for your help Stephan :)


In case something with WebView on Android does not work, I always try to make sure I set these crazy flags such as,

    WebSettings webSettings = webView.getSettings();    webSettings.setJavaScriptEnabled(true);    webSettings.setDomStorageEnabled(true);    webSettings.setLoadWithOverviewMode(true);    webSettings.setUseWideViewPort(true);    webSettings.setBuiltInZoomControls(true);    webSettings.setDisplayZoomControls(false);    webSettings.setSupportZoom(true);    webSettings.setDefaultTextEncodingName("utf-8");

I wonder why these are not set by Default, who would expect webpages without javascript content nowadays, and whats the use having javascript enabled when DOM is unavailable unless specified. Hope someone filed this as a bug or improvement/feature-request already and the monkeys are working on it.

and then there is deprecated stuff rotting somewhere, like this:

webView.getSettings().setPluginState(PluginState.ON);

All this for loading webpages inside app.

On iOS, its all so simple - Swift 3.0

private func openURLWithInAppBrowser(urlString:String) {    guard let url = URL(string:urlString) else {        return    }    let sfSafari = SFSafariViewController(url:url)    present(sfSafari, animated: true, completion: nil)}


Loading javascript in webview

webView.getSettings().setDomStorageEnabled(true);