开发者

android, webview, javascript injection

开发者 https://www.devze.com 2023-01-16 07:42 出处:网络
I\'d like to call a JavaScript function out of Java (Android). The following source code works fine for me (开发者_开发百科source).

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.


Use this code:

String js_str = "Your JS Code";

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号