Answer the question
In order to leave comments, you need to log in
Interaction of Java and JS applications?
There is an application in which you can execute scripts in JS. The task is to send e-mail from this application. I want to write an application for sending email in Java. The application runs on OS Windows.
How to organize the interaction of JS and java programs? What types of interaction exist?
In JS, you can create an ActiveXObject object and work with its fields and methods. Is it possible to organize work with a Java application in a similar way?
Or is it necessary to create a web service and send all requests to the Java application as http requests (not very convenient for local use)?
PS. Roman Roman- many thanks for the detailed answer. The fact is that I need to call the java method from js (a third-party program with its own functionality), and not call js from java. A program that executes a js script throws a "Java - definition is missing" error when I try to instantiate a java class in the script via Java.type
Answer the question
In order to leave comments, you need to log in
Hello. Probably the answer is not relevant in time, but I will comment. Might be useful to someone:
I used Java FX and its WebView element, got the browser window object and called back functions in javascript.
Getting the window object.
browser.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue ov, State oldState, State newState) {
if(newState == Worker.State.SUCCEEDED) {
JSObject jsobj = (JSObject) browser.getEngine().executeScript("window");
jsobj.setMember("bridge", jl);
}
}
});
private Bridge jl = new Bridge();
public class Bridge {
public String elementId() { //отправляем обратно в SVG
System.out.println("receive id");
return numberID;
}
public String elementIdText() {
if (numberID.startsWith("tspan")) {
String answer = "Java Callback";
iclick = true;
answer+=' '+ numberID;
return answer;
}
return "Finish";
}
}
function doCallbackText() {
var SVG = document.getElementById('Capa_1');
var path = bridge.elementId(); //читаем из приложения
var path1 = bridge.elementIdText();
if (path1!= "Finish") SVG.getElementById(path).textContent = path1;
console.log(path1+"Вставляю текст");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question