title: WebView's loadUrl("javascript:...") not working
body: <p>I am playing with Android's WebView: I have a sample text "asdf" which shall be dyed when the user clicks on a button (red, green or blue). To make things a little bit more complicated, the WebView first tells the Java code to trigger the color change and then from within Java the WebView is changed:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MainActivity extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final WebView myWebView = (WebView) findViewById(R.id.webview);
          WebSettings webSettings = myWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          webSettings.setDomStorageEnabled(true);
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
              WebView.setWebContentsDebuggingEnabled(true);
          }
  
          final WebAppInterface webAppInterface = new WebAppInterface(this, myWebView);
          myWebView.addJavascriptInterface(webAppInterface, "Android");
          myWebView.loadUrl("file:///android_asset/index.html");
      }
  }
  </code></pre>
  
  <p>This is the interface:</p>
  
  <pre><code>public class WebAppInterface {
  
      Context context;
      WebView webView;
  
      WebAppInterface(Context context, WebView webView) {
          this.context = context;
          this.webView = webView;
      }
  
      @JavascriptInterface
      public void dye(String color) {
          switch (color) {
              case "red":
                  webView.loadUrl("javascript:dyeRed()");
                  break;
              case "green":
                  webView.loadUrl("javascript:dyeGreen()");
                  break;
              case "blue":
                  webView.loadUrl("javascript:dyeBlue()");
                  break;
          }
      }
  }
  </code></pre>
  
  <p>In my html file there are 3 buttons like this one:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;button onClick="callDyeRed()"&gt;
      RED
  &lt;/button&gt; 
  </code></pre>
  
  <p>And inside a javascript file that gets successfully loaded I have functions like these:</p>
  
  <pre class="lang-js prettyprint-override"><code>function callDyeRed() {
    Android.dye("red");
  }
  function dyeRed() {
    document.getElementsByTagName('body')[0].style.color = 'red';
  }
  </code></pre>
  
  <p>When I click on the button I see that inside WebAppInterface the line <code>webView.loadUrl("javascript:dyeRed()")</code> is executed. Thus, the js->Java communication works. However, the opposite is not true: Javascript code is not executed afterwards.</p>
  
  <p>What am I missing here?</p>
  
  <p>If I change the color from within a WebViewClient, the communication works:</p>
  
  <pre class="lang-java prettyprint-override"><code>myWebView.setWebViewClient(new WebViewClient() {
      @Override
      public void onPageFinished(WebView webView, String url) {
          webView.loadUrl("javascript:dyeGreen()");
      } 
  }); 
  </code></pre>