6

My android application displays webpages(i used webview for it). .but javascript onthe wepage is not running in a webview .If i visit the same webpage through the Browser,javascript is running . How to run javascript in an application(using a webview)?

3 Answers 3

13

Enable Javascript! :

WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

WebView : setJavaScriptEnabled

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

2 Comments

mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); I tried both,they didnt work for me.
it also support for mathjax-config? because my webview client not display some math function i googled a lot but nothing works@Elenasys
7

From the Android documentation:

"By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView.

...

However, you can modify the WebSettings, such as enabling JavaScript with setJavaScriptEnabled()."

1 Comment

This answer is extremely importent OP, just because something CAN be done does not mean you should do it.
0

For Easy way you can use WebChromeClient, see in this video tutorial.

If you want more control with js, you can use method with addJavascriptInterface, but you must create your html-page for this method (). Look at this sample.

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.