According to the JavaFX docs, you can execute Java code with JavaScript function. Below is my code:
engine = webview.getEngine();
engine.load("http://localhost:8080/testing.php");
openExcel callback = new openExcel();
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("app", callback);
The above is in the initialize method, then for the other class(openExcel) I've got something like this:
public class openExcel {
public void open() {
if (Desktop.isDesktopSupported()) {
try {
File myFile = new File("C:\\Users\\HP\\Desktop\\v3.01.xlsm");
Desktop.getDesktop().open(myFile);
} catch(IOException ex) {
System.out.println("Your application is not support");
}
}
}
}
HTML file:
<html>
<head>
<script>
function openExcel() {
app.open();
alert('hello world');
}
</script>
</head>
<body>
<button onclick="openExcel()">Open excel</button>
</body>
The problem that I'm facing is that when I click in the button "openExcel" it does nothing? I need help!