如何将数据从JavaScript传递到JavaFX [英] How to pass data from JavaScript to JavaFX
本文介绍了如何将数据从JavaScript传递到JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的JavaFX应用程序中,我有一个WebView来加载HTML内容。有没有办法传递Javascript变量并在JavaFX App中操作它。假设我在Javascript中有一个变量 FULLNAME
,我想在JavaFX的TextField中显示它。可能吗?你能给出一个例子。
In my JavaFX application, I have a WebView to load HTML contents. Is there a way to pass Javascript variables and manipulate it in JavaFX App. Let's say I have a variable FULLNAME
in Javascript and I want to display it in a TextField in JavaFX. Is it possible? Can you give an example.
推荐答案
这是可能的 - 假设你的webview在 webView中
变量,并且您希望将 FULLNAME
变量加载到 fullNameField
中,尝试在Java端执行此操作:
It is possible - assuming your webview is in a webView
variable, and you want your FULLNAME
variable loaded into fullNameField
, try executing this on the Java side:
String fullName = (String) webview1.getEngine().executeScript("FULLNAME;");
fullNameField.setText(fullName);
这篇关于如何将数据从JavaScript传递到JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文