I want to call a javascript function from android activity, but it does not work. I used the android webview function webview.loadUrl ("javascript: function ()"); This is my Android code:
package com.example.web; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.webkit.WebView; public class MainActivity extends Activity { WebView webview; int i=30; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webview = (WebView)findViewById(R.id.webView1); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("file:///android_asset/index.html"); webview.loadUrl("javascript:change(i)"); } @Override public boolean onCreateOptionsMenu(Menu menu) {
This is my html code:
<html> <body> <div id="texta">text</div> <script> function change(num){ document.getElementById("texta").innerHTML=num; } </script> </body> </html>
source share