Java FX liveconnect - calling javascript function from FX application

666 Views Asked by At

I am facing a problem, I need to communicate from Java FX application to browser. Prior to that I found info as:

var jsObject = netscape.javascript.JSObject.getWindow(applet);
jsObject.call("show_alert", []);

With this I can access JavaScript function. But my Java FX application is not an applet (not implementing JApplet). So what could I give as input to getWindow().

Any Suggestion?

1

There are 1 best solutions below

0
disrvptor On

Reading the comments it is unclear if you're JavaFX code is running embedded within a web browser page (in other words an applet) or it is some other configuration. However, you should start by using the following.

JSObject jsWin = getHostServices().getWebContext();
if (jsWin != null) {
    jsWin.eval("show_alert();");
}

If this doesn't work then please comment with what's not working and what the specific run-time configuration is.

getHostServices() is a method on a JavaFX Application as documented here and here.