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.
Add a comment
|
1 Answer
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);
6 Comments
Ethyl Casin
Wow! Just that simple?
Evan Knowles
Yep - check here for more: blogs.oracle.com/javafx/entry/…
Uluk Biy
The code should be run after the webengine is completed loading the html. Namely when the state is SUCCESSED.
Ethyl Casin
@Evan Knowles, Sir, is it possible to add a changelistener so that if the javascript variable will change the javafx variable also changes. I mean if FULLNAME will change , the Javafx TextField will also change? Is it possible?
Eric Duminil
@UlukBiy:
State.SUCCEEDED |