Calling javascript functions from webview Android
<p>I have a webview and it is loaded with a html file.</p>

<p>Now that I want to call the Javascript function DataInput() from the webview.</p>

<p>Here is my code.But the console returns </p>

<pre><code>E/Web Console(435): Uncaught ReferenceError: DataInput is not defined:1
</code></pre>

<p>Does anybody know why? Thanks!</p>

<pre><code>WebView engine = (WebView) (findViewById(R.id.webView1));

    engine.setWebViewClient(new WebViewClient());
    engine.setWebChromeClient(new WebChromeClient() {
          public boolean onConsoleMessage(ConsoleMessage cm) {
                Log.d("MyApplication", cm.message() + " -- From line "
                                     + cm.lineNumber() + " of "
                                     + cm.sourceId() );
                return true;
              }
            });
    engine.getSettings().setJavaScriptEnabled(true);
    engine.getSettings().setPluginsEnabled(true);

    engine.loadUrl("file:///" + path);
    engine.loadUrl("javascript:DataInput()");
</code></pre>

<p>My html files includes the following code:</p>

<pre><code>&lt;script type="text/javascript"&gt;    
function DataInput( )
{   
  $( "video" ).each( function(e){this.play();}   );
  $( "video" ).bind( "ended", function(e){this.play();});
}
&lt;/script&gt;
</code></pre>

<p>FURTHER EDIT:::::</p>

<p>I added a button and calls the JS upon onclick and it (kinda) worked... i.e.</p>

<pre><code>public void onClick(View arg0) {
    engine.loadUrl("javascript:DataInput()");

}
</code></pre>

<p>How come???? I really really do want to know why..... </p>

<p>P.S. I said (kinda) work because the video did autoplay (due to $( "video" ).each( function(e){this.play();}   );) but does not loop ($( "video" ).bind( "ended", function(e){this.play();}); &lt;&lt;&lt; not working)</p>
