'Nashorn - Java8 - declare Window & typeof globalThis
I want to invoke JavaScript code into my Java code, I tried to use Nashorn. When I try to run my I code I got an error that window is not recognized (ReferenceError: "window" is not defined in at line number 1)
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine engine = engineManager.getEngineByName("nashorn");
String script = "if(window.ServicesXXXX== null) {\n"
+ " window.ServicesXXXX.stopInv();}";
try {
engine.eval(script);
} catch (ScriptException e) {
LOGGER.info("Error in the invoque of js", e.getMessage());
}
My question is how to declare var window: Window & typeof globalThis ?
Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
