Execute function from .js with J2V8

I am using J2V8 to execute JavaScript code on Android. In my Java code, can I access and execute the JavaScript functions of a separate .js file? If possible, how can I do this?

Thanks:

Bernat

+5
source share
1 answer

As with many JavaScript environments, you simply load a script that contains other functions that you want to run an example browser . Any functions that are added to the global scope are now available to you:

V8 v8 = V8.createV8Runtime(); v8.executeScript(readFileAsString("script1")); // contains the function foo(); v8.executeScript(readFileAsString("script2")); // contains the function bar(x, y); v8.executeJSFunction("foo"); v8.executeJSFunction("bar", 7, 8);

+5
source

All Articles