1

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 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

6 Comments

Wow! Just that simple?
Yep - check here for more: blogs.oracle.com/javafx/entry/…
The code should be run after the webengine is completed loading the html. Namely when the state is SUCCESSED.
@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?
@UlukBiy: State.SUCCEEDED
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.