Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute function from .js with J2V8

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

like image 227
konbernu Avatar asked Aug 09 '16 10:08

konbernu


1 Answers

Like with many JavaScript environments, you simply load the script that contains the other functions you wish to execute browser example. 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);

like image 110
irbull Avatar answered Oct 10 '22 12:10

irbull