Issue
I am trying to execute an arbitrary Javascript function on an Android WebView and get its result. To invoke the function, I use loadUrl() and I have also added a Javascript interface that is supposed to be called with the result. This is what the JS looks like that I am trying to execute from loadUrl():
(function () {
var res = eval(foo());
MyInterface.setResult(res);
})()
foo
stands in for the name of the function I am trying to invoke and MyInterface
is the interface that I added earlier. When I do this, foo()
does get invoked but the next call does not. I tried changing MyInterface.setResult(res);
to simpler JS statements like console.log("finished")
but nothing is executed after eval()
. If I remove eval
the next statement is executed. Any idea on what's going on here?
Solution
eval takes a string. It's trying to invoke a string foo is returning.
Try eval("foo()");
edit: you could just call the function without eval as well.
Answered By - craniumonempty
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.