home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Enabling LiveConnect

By default in Netscape Navigator, Java and JavaScript are enabled—whenever these languages are enabled, LiveConnect is enabled as well. To confirm that they are enabled in your copy of Navigator, choose Edit, Preferences. Then, in the Categories list, select Advanced, make sure that the Enable Java and Enable JavaScript boxes are checked, and then click OK.


What About Internet Explorer?

As you might expect, Microsoft Internet Explorer does not explicitly support the LiveConnect technology. However, this doesn’t mean that Internet Explorer authors and users are left out in the cold. Far from it.

The foundation of Microsoft’s Web offerings is its ActiveX technology. These are a series of Web capabilities that enable authors to make use of scripting, ActiveX Controls, and Navigator plug-ins, and view and edit legacy documents (such as Microsoft Word documents) right in their Internet Explorer window. The ActiveX technologies were designed to enable the different components running within Internet Explorer to communicate with one another.

Although Internet Explorer does not support LiveConnect per se, its ActiveX technology achieves the same thing. Later in this chapter, you will find out how to control ActiveX Controls within Microsoft Internet Explorer using JavaScript.


The Java Console

Netscape Navigator has a Java Console that can be displayed by choosing Window, Java Console. Messages sent using java.lang.System.out or java.lang.System.err appear in this console.

Now, because of the communication possible between JavaScript and Java using LiveConnect, messages can be sent to the Java Console from JavaScript as well. To write a message to the Java Console from JavaScript, use the println method of java.lang.System.out or java.lang.System.err, as in the following:

java.lang.System.err.println(“JavaScript checkpoint #1”)

You can use the Java Console to help debug JavaScript applications. Output messages and intermediate values to the Java Console and watch it while browsing your pages. If you create JavaScripts to validate HTML forms, for instance, while you are debugging the scripts, you can print out intermediate form data to the console.

The Netscape Packages

Netscape Navigator includes several Java packages used to enable LiveConnect communication. The first, netscape, is used to enable communication back and forth between JavaScript and Java applets. Additionally, replacement java and sun packages are provided. These feature security improvements for LiveConnect. The following netscape packages are included:

  netscape.javascript—This package implements the JSObject and JSException classes, which enable Java applets to access JavaScript properties and throw exceptions when JavaScript returns an error.
  netscape.plug-in—This package implements the Plugin class, which enables cross communication between JavaScript and plug-ins. Plug-ins must be compiled with this class to make them LiveConnect compatible.
  netscape.applet and netscape.net—These are direct replacements for the sun.applet and sun.net classes provided in Sun’s Java Development Kit.
  See “Leveraging Java Classes and Packages,” p. 984.

JavaScript to Java Communication

With LiveConnect, JavaScript can make calls directly to Java methods. As already shown in the “Java Console” section, this is how JavaScript can output messages to the Java Console. To JavaScript, all Java packages and classes are properties of the packages object. Therefore, the full name of a Java object in JavaScript would be something like Packages.packageName.className.methodName.


The packages name is optional for the java, sun, and netscape packages.

Java applets can be controlled through JavaScript without knowing too much about the internal construction of the applet, as long as a few conditions are true. The first step is to attach a NAME attribute to the <APPLET> tag when including the Java applet in your HTML document. Then all public variables, methods, and properties of the applet are available for access to JavaScript.

Any time you want to pass information into a Java applet, you might want to consider using JavaScript to do this. If you have a Java applet that implements a calendar, for example, you could create an HTML form with attached JavaScripts to enable the user to select what month should be displayed. By using JavaScript in this way, you avoid the need to give the applet itself the capability to interact with the user. Netscape shows a simple demo of controlling a Java applet by using JavaScript at http://developer.netscape.com/docs/technote/javascript/liveconnect/Fade.html.

The Java applet is included in the HTML document by using the following:

<APPLET CODE=“Fade.class” NAME=“Fader” WIDTH=400 HEIGHT=100>
<PARAM NAME=“text1” VALUE=“Look at this text carefully!”>
<PARAM NAME=“url1”  VALUE=“<http://www.netscape.com>”>
<PARAM NAME=“font1” VALUE=“Helvetica,PLAIN,36”>
</APPLET>

The name Fader attached to the applet is how the Java applet is controlled. When any of the parameters entered in the form elements are changed, one of the public Java methods of this applet (setFont, setText, setUrl, setAnimateSpeed, or setBackgroundColor) is called through its onChange event.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.