0

I'd like to call a JavaScript function out of Java (Android).

The following source code works fine for me (source).

 /**
  * This is not called on the UI thread. Post a runnable to invoke
  * loadUrl on the UI thread.
  */
  public void clickOnAndroid() {
    mHandler.post(new Runnable() {
      public void run() {
        mWebView.loadUrl("javascript:wave()");
      }
    });
  }

My problem now is to use a parameter for the JavaScript function.

Let's assume I've got some XML (just like AJAX somehow).

I need to escape it just like the iPhone / Objective-C command stringByEvaluatingJavaScriptFromString does.

0

1 Answer 1

-1

Use this code:

String js_str = "Your JS Code";

webview.loadUrl("javascript:"+js_str);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.