【发布时间】:2018-02-23 19:45:05
【问题描述】:
根据 JavaFX 文档,您可以使用 JavaScript 函数执行 Java 代码。以下是我的代码:
engine = webview.getEngine();
engine.load("http://localhost:8080/testing.php");
openExcel callback = new openExcel();
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("app", callback);
上面是在初始化方法中,然后对于另一个类(openExcel)我有这样的东西:
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 文件:
<html>
<head>
<script>
function openExcel() {
app.open();
alert('hello world');
}
</script>
</head>
<body>
<button onclick="openExcel()">Open excel</button>
</body>
我面临的问题是,当我单击“openExcel”按钮时,它什么也不做?我需要帮助!
【问题讨论】:
标签: javascript java javafx javafx-webengine