Is it possible to pass a function/callback from javascript to a java applet?
For example i have an applet with a button that when pressed it will call the passed js callback
function onCommand() {
alert('Button pressed from applet');
}
applet.onCommand(onCommand);
Is it possible to pass a function/callback from javascript to a java applet?
For example i have an applet with a button that when pressed it will call the passed js callback
function onCommand() {
alert('Button pressed from applet');
}
applet.onCommand(onCommand);
Share
Improve this question
edited Sep 20, 2017 at 22:36
P.S.
16.4k14 gold badges65 silver badges86 bronze badges
asked Sep 24, 2008 at 11:38
kenken
5,0864 gold badges32 silver badges26 bronze badges
3 Answers
Reset to default 4I tend to use something I derived from the reflection example at the bottom of this page, as then you don't need to meddle with your classpath to get it to pile
Then I just pass JSON strings around between the applet and javascript
You can use JSObject to call back into javascript from Java.
From that page:
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
public void init() {
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
JSObject loc = (JSObject) doc.getMember("location");
String s = (String) loc.getMember("href"); // document.location.href
win.call("f", null); // Call f() in HTML page
}
}
ps. to use JSObject you may need to include "MAYSCRIPT" tag to applet html tag.