Entry
How can my applet call into JavaScript?
Feb 25th, 2000 08:44
Martin Honnen, Netscape client side JavaScript guide and reference docs
Applets which have the
MAYSCRIPT
attribute set(for instance
<APPLET NAME="anApplet" MAYSCRIPT ...>
or
<EMBED NAME="anApplet" MAYSCRIPT="true">
if you use the java plugin)
can call into Javascript by importing
import netscape.javascript.*;
and then at least instantiating
JSObject window = JSObject.getWindow(this);
the JavaScript window object. Now your Java code can follow the
Javascript object hierachy e.g.
JSObject document = window.getMember("document")
JSObject forms = document.getMember("forms");
or set properties with
window.setMember ("aVariable", "Kibology");
or eval code
window.eval("alert('Kibology');");
or call methods of JavaScript objects
String args[] = new String[1];
args[0] = "Kibology";
window.call ("alert", args);
A Java applet calling into JavaScript is part of what Netscape calls
Liveconnect and is around in NN3+ and at least IE5, IE4 seems to depend
on the JVM you have installed.