JavaScript: The Definitive Guide

Previous Chapter 19
LiveConnect: JavaScript and Java
Next
 

19.7 Working with Java in Internet Explorer

Internet Explorer 3.0 does not support LiveConnect. Instead, it treats Java applets as ActiveX objects and allows JavaScript to interact with them through that mechanism. This gives Internet Explorer some, but not all, of the capabilities of LiveConnect.

Interacting with Applets

Internet Explorer 3.0 can invoke the public methods of Java applets and can read and write the values of public fields of Java applets, in much the same way that Navigator 3.0 can. Although the underlying mechanism is different, the basic syntax is the same:

document.appletname.property
document.appletname.method(...)

The data conversion that occurs when Internet Explorer passes values back and forth to Java follows ActiveX's rules, and is not documented here.

There are a couple of restrictions on IE 3.0 interactions with applets. First, note that it does not support the applets[] array of the Document object. So if you want to read or write properties or invoke methods of an applet, you must call the applet by name, and you must assign a name to the applet with the NAME attribute of the <APPLET> tag.

Second, note the Internet Explorer can only read and write properties and invoke methods of the applet object itself. IE does not have an equivalent to the LiveConnect JavaObject object, so if an applet has a property that refers to some other Java object, IE cannot read and write properties or invoke methods of that other object. To work around this shortcoming, you simply need to be sure that all functionality you need to access from JavaScript is implemented as a method of the applet, even if some of those methods do nothing more than invoke a method of some other object.

Third, Internet Explorer can only invoke the public instance methods of an applet. It has no mechanism for invoking with Java class methods.

Interacting with Plug-Ins and System Classes

Internet Explorer 3.0 can install and use Navigator plug-ins, but it does not allow JavaScript to interact with them in the way that Navigator does. Similarly, it does not have JavaPackage or JavaClass objects, and so has no way to read or write properties of system classes, invoke methods of system classes or create instances of system classes.

Calling JavaScript from Applets

Internet Explorer does not support the netscape.javascript.JSObject class, and does not allow Java applets to invoke JavaScript methods or read and write JavaScript properties.

Microsoft's ActiveX technology does allow Java applets in IE to interact with OLE objects embedded in a web page, as long as the applet is compiled so that it supports the desired object and as long as JavaScript passes a reference to the OLE control to the applet. Once JavaScript has told the applet where it can find the OLE control, any interaction occurs directly between the applet and the OLE object, without the intervention of JavaScript. This differs from the LiveConnect model in which an applet can use JavaScript as an intermediary to control any arbitrary applet or plug-in without special compilation being required to enable direct communication between the first applet and the other applet or plug-in.


Previous Home Next
Using JavaScript from Java Book Index Summary

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