Main Page

Java Applets

} else {
//no way to detect!
return false;
}
}
This function uses object detection to determine which methodology to use. If
navigator.mimeTypes
is
available, then the function checks for an installed plugin using Netscape-style plugin detection. If, on
the other hand, it’s possible to create
ActiveXObject
objects, it uses the IE-style of detection. If neither
of these options is available (which isn’t very likely), the function just returns
false
.
To detect specific plugins, you can customize this algorithm and create a whole host of plugin detection
functions.
Java Applets
The oldest form of plugin, the Java applet has recently been redefined to work with the generic browser
plugin framework. Previously, applets had to be loaded using the
<applet/>
element. HTML 4.0 depre-
cated
<applet/>
, favoring
<object/>
as the sole means for embedding plugins. To aid in this move,
Sun Microsystems created the Java Plugin, which is included as part of the Java Runtime Environment
(JRE) and is available at
http://java.sun.com/
.
Embedding applets
Embedding an applet requires you to use the nonstandard
code
property of
<object/>
to specify the
class to load. Although all browsers should work when using
data
for the same purpose, the reality is
that support isn’t yet universal. So, in the interest of cross-browser compatibility, it’s best to use
code
in this way:
<object type=”application/x-java-applet”
code=”ExampleApplet.class” width=”100” height=”100” id=”ExampleApplet”>
</object>
Note the mime type for Java applets is
application/x-java-applet
. By specifying this, you are sure
that the browser will use the most appropriate (and available) version of the Java plugin. You can
optionally specify the exact version required by adding it to the end of the mime type. For example, to
specify version 1.4.2 (from JRE 1.4.2), add
“jpi-version=1.4.2”
:
<object type=”application/x-java-applet;jpi-version=1.4.2”
code=”ExampleApplet.class” width=”100” height=”100” id=”ExampleApplet”>
</object>
Macromedia provides a Flash Detection Kit, available at
http://www.macromedia
.com/software/flash/download/detection_kit
/, which can be used to produce
cross-browser HTML and JavaScript for embedding Flash movies.
543
Interacting with Plugins
21_579088 ch18.qxd 3/28/05 11:43 AM Page 543


JavaScript EditorFree JavaScript Editor     Ajax Editor


©