execute function from .js with J2V8

倖福魔咒の 提交于 2019-12-07 05:02:41

问题


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?

Thank you:

Bernat


回答1:


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);



来源:https://stackoverflow.com/questions/38848274/execute-function-from-js-with-j2v8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!