I have been trying to pass a variable that I created so that you could specify which server to connect to when loading a WebView in JavaFX. The way in which my application is set up is that it basically is emulating a webpage in JavaFX. It creates a Scene, sets it to a Stage and calls show(). Initialize is overridden and a URL is created that represents a file path to the HTML file. load() is then called on this URL. Is there any way I can get the Javascript to know about the variable from JavaFX at the time of the load()?
For example:
public class MyClass implements Initializable
{
@FXML
private WebView wWeb;
private String server = "xyz:server";
@Override
public void initialize(URL url, Resource rb)
{
URL urlContent = getClass().getResource("index.html");
wWeb.getEngine().load( urlContent.toExternalForm() );
}
}
I have tried adding the server after the .html by adding "?server=" + server, but JavaFX thinks that the entire String is the file name and can't find a file with that exact name. It shouldn't be this difficult to pass a DOM from Java to Javascript at load time. Any help would be great. I have been looking for a solution for a while now and have read many S.O. pages but none have addressed the problem.
wWeb.getEngine().load( urlContent.toExternalForm() + "?server=" + server)work? or is that what you already tried?urlContent.toExternalForm() + "?server=" + server), what do you see? Can you post what the value of that full url is?