android, webview, javascript injection
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);
精彩评论