If jsCode is:
function() {
return "test"
}
I can do:
String js = "(" + jsCode + ") ();"
mWebView.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
Log.d("return value: ", s); // Returns the value from the function
}
});
to run the javascript code and get "test" as a value back in Java
But what if I need more complex javascript code, for example:
function() {
return test();
}
function test() {
return "test";
}
, which defines a function test() and calls it;
Passing this javascript code to webview's evaluateJavascript gives error: "Uncaught SyntaxError: Unexpected token function", source: (1)