title: Load a javascript method from Android Webview
body: <p>I am trying to render a chart in an Android WebView using HighCharts.</p>
  
  <p>What my app does should be simple :
  - Load the HTML page and external (but local) css and js files
  - Load data from the Java part of the app
  - Call a javascript function with the previously-loaded data as a parameter</p>
  
  <p>I setup my webview by activating Javascript :</p>
  
  <pre><code>mWebView.getSettings().setJavaScriptEnabled(true);
  </code></pre>
  
  <p>And also by setting a WebClient to catch javascript's console messages :</p>
  
  <pre><code>mWebView.setWebChromeClient(new WebChromeClient() {
          public boolean onConsoleMessage(ConsoleMessage cm) {
              Log.d(TAG, cm.message() + " -- From line "
                      + cm.lineNumber() + " of "
                      + cm.sourceId() );
              return true;
          }
  
      });
  </code></pre>
  
  <p>This is my HTML page :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="fr"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
      &lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
      &lt;title&gt;Chart&lt;/title&gt;
      &lt;script src="jquery.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;script src="highstock.js"&gt;&lt;/script&gt;
      &lt;script src="exporting.js"&gt;&lt;/script&gt;
      &lt;script language="javascript"&gt;
          function plot() {
              console.log("Hello !");
          }
      &lt;/script&gt;
      &lt;div id="container" style="height: 100%; width: 100%"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I load this page from the app's assets by calling </p>
  
  <pre><code>mWebView.loadUrl("file:///android_asset/page.html");
  </code></pre>
  
  <p>My external CSS file seems to be read and I suppose the external JS files are also correctly loaded</p>
  
  <p>I read everywhere that I can call my javascript method anytime by calling</p>
  
  <pre><code>mWebView.loadUrl("javascript:plot()");
  </code></pre>
  
  <p>However, I always get the error </p>
  
  <blockquote>
    <p>Uncaught ReferenceError: plot is not defined -- From line 1 of null</p>
  </blockquote>
  
  <p>Is there anything I might have forgotten ?
  Note that I load my page and call the javascript method right after the loadUrl call.</p>
  
  <p>Thanks !</p>