How to pass data from JavaScript to JavaFX

妖精的绣舞 提交于 2019-12-02 08:06:14

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/30389458/how-to-pass-data-from-javascript-to-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!