JavaScript embedded in Java (Definition)

Java applets can contain JavaScript code fragments that can be executed by the applet.

You can embed fragments of JavaScript inside Java applets although there are some limitations to what you can accomplish with this. For this to work, Java and JavaScript both have to be enabled and working. This may require some preference setting. Currently, it only works in Netscape.

The <APPLET> tag is the main way to embed a Java applet within an HTML document. That much generally works across all browsers.

JavaScript scripts should always have access to all the internals of a Java applet that it cares to make publicly available. However, the converse is not necessarily true. Java applets may not access the script-owned object space unless you give them permission to do so.

This is done with the MAYSCRIPT tag attribute on the <APPLET> tag.

The Java applet can then mimic JavaScript methods using the Java syntax, and there are mechanisms for accessing eval() functionality for interpreting JavaScript source text.

See also:Java, Java exception events, JSObject object, MAYSCRIPT


Wrox Instant JavaScript - page - 57