Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Javascript in HTML file from within Android

I am using Android and I have an HTML file which contains some Javascript. However, I am not able to get the Javascript code to execute. What do I need to do in order to run this code? Thanks in advance for any help.

like image 403
raj Avatar asked Apr 18 '11 14:04

raj


2 Answers

Call getSettings().setJavaScriptEnabled(true) on your WebView, as JavaScript is disabled by default.

like image 195
CommonsWare Avatar answered Oct 20 '22 13:10

CommonsWare


@raj asked for credible and/or official sources

@CommonsWare answered:

Call getSettings().setJavaScriptEnabled(true) on your WebView

A simple search for the Android documentation provides the following official sources:

  • https://developer.android.com/reference/android/webkit/WebView.html
  • https://developer.android.com/reference/android/webkit/WebSettings.html#setJavaScriptEnabled%28boolean%29
like image 25
dsh Avatar answered Oct 20 '22 11:10

dsh