Java to JavaScript Communication

The first step in enabling your Java applets to access JavaScript properties is to import the javascript package into your Java applet, as shown here:

import netscape.javascript.*

This enables the Java applet to access JavaScript properties through the JSObject class. However, the author of the HTML document must still enable access to his JavaScript by including the mayscript attribute in the <applet> element used to include the Java applet. If the Fader used in the last example needed to access JavaScript, for example, the <applet> element would look like the following:

 <applet code="Fade.class" name="Fader" mayscript="mayscript" width="400" height="100"> <param name="text1" value="Look at this text carefully!" ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.