title: Android WebView Unable to find JavaScript function
body: <p>i am trying to call JS function from android activity it loads the page in webview but couldn't find out the JS function , the function is working very fine in desktop browser</p>
  
  <p><strong>Here is the JAVA Code</strong></p>
  
  <p>setting almost each and everything  for JS </p>
  
  <pre><code>    index = (WebView) findViewById(R.id.edit);
      WebSettings Websettings = index.getSettings();
      Websettings.setBuiltInZoomControls(true);
      Websettings.setSupportZoom(true);  
      Websettings.setJavaScriptEnabled(true);
      Websettings.setBuiltInZoomControls(true); 
      Websettings.setRenderPriority(RenderPriority.HIGH);
      index.getSettings().setPluginState(PluginState.ON);
      index.setWebChromeClient(new WebChromeClient());
  </code></pre>
  
  <p>and here is how i am calling JS function</p>
  
  <pre><code>index.loadUrl("file:///android_asset/demo.html");
  index.loadUrl("javascript:getList('"+JsonString+"');"); 
  </code></pre>
  
  <p><strong>Here is the JS function</strong></p>
  
  <pre><code>function getList(jString) 
  {
  alert('function called');
  }
  </code></pre>
  
  <p><strong>Here is what the LogCat Says</strong></p>
  
  <pre><code>04-24 16:44:58.015: E/Web Console(31516): Uncaught ReferenceError: 
  getList is not defined:1
  </code></pre>
  
  <p><strong>Update: Solution:-</strong></p>
  
  <p>As Paul Lammertsma sugessted, i was not waiting for html page to load fully and was calling the JS function rite after loading html page in webView. so by calling JS function in onPageFinished solved my problem
  this worked for me:</p>
  
  <pre><code>index.setWebViewClient(new WebViewClient() {
                          @Override
                          public void onPageFinished(WebView view, String url) {
                              index.loadUrl("javascript:getList('"+JsonString+"');"); 
                          }
  
                      });
  </code></pre>