JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

JSObject Java Class

Name

JSObject Java Class--- Java representation of a JavaScript object

Availability

In the netscape.javascript package included with Navigator 3.0

Synopsis

public final class netscape.javascript.JSObject extends Object

Methods

call()

Invoke a method of the JavaScript object.

eval()

Evaluate a string of JavaScript code in the context of the JavaScript object.

getMember()

Get the value of a property of the JavaScript object.

getSlot()

Get the value of an array element of the JavaScript object.

getWindow()

Get a "root" JSObject that represents the JavaScript Window object of the web browser.

removeMember()

Delete a property from the JavaScript object.

setMember()

Set the value of a property of the JavaScript object.

setSlot()

Set the value of an array element of the JavaScript object.

toString()

Invoke the JavaScript toString() method of the JavaScript object, and return its result.

Description

The JSObject is a Java class, not a JavaScript object; it cannot be used in your JavaScript programs, Instead, the JSObject is used by Java applets that wish to communicate with JavaScript by reading and writing JavaScript properties and array elements, by invoking JavaScript methods, and by evaluating and executing arbitrary strings of JavaScript code. Obviously, since JSObject is a Java class, you must understand Java programming in order to use it.

A Java applet that wishes to use the JSObject class must obtain an initial JSObject instance that represents the web browser window that the applet is running in. The JSObject class does not define a constructor method, so the only way to obtain this initial instance is by invoking the static getWindow() method, and passing it the java.applet.Applet instance that represents the applet. This static method returns a "root" JSObject instance, and you can use the getMember() and getSlot() methods to obtain any other JSObjects that the applet requires.

Note that if an applet uses the JSObject class, it must have the MAYSCRIPT attribute set in its <APPLET> tag, or it will not be allowed to manipulate JavaScript from Java. Also, an applet that uses the JSObject class should import the class with a line like the following:

import netscape.javascript.JSObject;
To compile an applet that uses JSObject, the compiler must be able to locate that class. Depending on the vendor of your compiler, this is usually done by setting your CLASSPATH environment variable. The actual class file for the JSObject class is found in the java_30 file that is part of the Navigator 3.0 distribution.

Full details on programming with the JSObject can be found in Chapter 19, LiveConnect: JavaScript and Java.

See Also

Chapter 19, LiveConnect: JavaScript and Java


Previous Home Next
JavaPackage Book Index JSObject.call()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell