home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


JavaScript: The Definitive Guide

Previous Chapter 19 Next
 

19. LiveConnect: JavaScript and Java

Navigator 3.0 opens up a tremendous new set of programming possibilities by allowing JavaScript to communicate with the Java virtual machine running in the browser. Netscape's name for this new JavaScript-to-Java and Java-to-JavaScript communication facility is "LiveConnect." This chapter explains how LiveConnect works, and how you can use it in your programs.

Note that Internet Explorer 3.0 does not support LiveConnect. Instead, it treats Java applets as ActiveX objects and allows them to be scripted through that mechanism. Doing so is described briefly at the end of this chapter.

To use LiveConnect, you'll need to understand Java programming. This chapter assumes you have at least a basic familiarity with Java (see Java in a Nutshell, by David Flanagan, and Exploring Java, by Patrick Niemeyer and Joshua Peck, both published by O'Reilly).

19.1 Overview of LiveConnect

LiveConnect is the mechanism that allows JavaScript and Java to work together. Using LiveConnect, all of the following are possible:

  • JavaScript programs can interact with the standard Java system classes built-in to the browser.

  • JavaScript programs can interact with Java applets, both reading and writing public fields of the applet and invoking public methods of the applet.

  • JavaScript programs can interact with Java-enabled Navigator plug-ins in the same way.

  • Applets and Java-enabled plug-ins can interact with JavaScript, reading and writing JavaScript object properties and array elements, and invoking JavaScript functions.

The surprising thing about LiveConnect is how easy it makes it to accomplish these difficult things. LiveConnect automatically handles all the required communication and data type conversion that must take place to allow Java and JavaScript to work together. LiveConnect is an underlying communication framework that opens up all sorts of possibilities for communication among JavaScript programs, Java applets, and Java-enabled plug-ins. LiveConnect can be thought of as the glue that ties these things together. Figure 19.1 illustrates this.


Previous Home Next
Compatibility Through CGI Scripts Book Index LiveConnect Data Types

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