While searching for an answer in google, it seems that I\'m not the only one stuck with a problem that seems impossible to solve.
I\'ve managed to create a WebView w
Do "Javascript-URLs" get routed through shouldOverrideUrlLoading
? Try checking that and if so, return false
for links like that (so that the webview handles the link, not your WebViewClient)
How enable programmatically answered in other answers. But some javascripts not worked if your webview is in nestedscrollview. Remove it and add webSettings.setJavaScriptEnabled(true);
What happened in my case : I was serving local html files and when applying
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
but then my urls stopped working. Solution to make both JS and local href work was to add
web.getSettings().setAllowFileAccess(true);
web.getSettings().setAllowFileAccessFromFileURLs(true);
where
web = (WebView) findViewById(R.id.embedded_web);
Try this to enable javascript
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl(url);
The proper way to enable JavaScript is by add the below two lines:
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
Even if after adding its not working then try adding the below line.
mWebView.getSettings().setDomStorageEnabled(true);
Now It should work. :)
I don't know what your exact problem is, but i can enable the JavaScript and a custom WebViewclient
without any problem:
WebView vistaWeb = (WebView) findViewById(R.id.webview);
vistaWeb.setWebChromeClient(new MyCustomChromeClient(this));
vistaWeb.setWebViewClient(new MyCustomWebViewClient(this));
vistaWeb.clearCache(true);
vistaWeb.clearHistory();
vistaWeb.getSettings().setJavaScriptEnabled(true);
vistaWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);