Javascript-Applet communication: how to pass return values back to Javascript
-
15-06-2021 - |
Question
I have some javascript code that needs to call a method in an applet. The applet and the javascript are running in the same webpage. I know how to call applet methods from javascript and vice versa (e.g., using MyAppletID.appletMethodName(args)
and JSObject
, respectively), but both of these techniques only allow one-way communication. They don't permit return values to be passed from one language back to the other.
I'd like to be able to do something like this...
var result = 0;
callAppletMethod( JSON.stringify(args), function(r) { result = r; } )
... to call an applet method and store the return value in result
.
Can anyone suggest a technique, library or toolkit that implements this sort of two-way Javascript-Applet communication?
Should I consider using a remote procedure call protocol like JSON-RPC? Or is there a better approach?
(I'm new to javascript and web programming.)
La solution
var result = MyAppletID.appletMethodName(args)
... should work fine to get a result from Java out to JavaScript.