问题
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