Execute javascript function from java

I want to know if javascript function can be executed from java. Basically, I have a javascript function to which I want to pass a string and then get the output from this function.

If possible, how to do it?

EDIT -

I could not find a solution to this question, what I did was to rewrite all javascript code in Java. But I guess Rhino ported to Android should do the trick. If someone tried, send a solution.

+6
source share
2 answers

Javascript is not supported in Java. If you need it, you can implement the Rhino javascript engine for this.

"Rhino is an open source JavaScript implementation written entirely in Java. It is usually embedded in Java applications to provide scripts to end users."

+2
source

You probably want to take a look at ScriptEngine . There are many examples of how to use them. It works on anything but a Mac, where for some reason they chose to include AppleScript instead of the default JavaScript.

Edit: take a look at this page , there seems to be a Rhino port for Android.

+3
source

Source: https://habr.com/ru/post/902529/


All Articles