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 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With