Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
You can deploy applets for users of both Internet Explorer and the Mozilla family of browsers in one of two ways:
- Through pure HTML
- Through JavaScript
When using a pure HTML approach to deploy applets in a mixed-browser environment, note the following:
- Internet Explorer
- Recognizes the
object
tag- Ignores the contents of the
comment
tag- Mozilla browsers
- Ignore an
object
tag with theclassid
attribute- Interpret the contents of the
comment
tagConsider the following example code from an HTML page:
<object classid="clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA" <param name="code" value="Applet1.class"> <comment> <embed code="Applet1.class" type="application/x-java-applet;jpi-version=1.5.0"> <noembed> No Java Support. </noembed> </embed> </comment> </object>
Instead of using the pure HTML approach described above, you can use JavaScript to deploy applets in a mixed-browser environment.
Through JavaScript, you:
- Detect the user's browser through the
appName
variable.- Use the
document.write()
method to write a tag based on the value of theappName
variable:
- If the browser name equals "Netscape", write the
embed
tag.- If the browser name equals "Microsoft Internet Explorer", write the
object
tag.In the following example, the
document.write()
method outputs either anembed
orobject
tag for each user “on the fly”:<html> <script language="Javascript"> var _app = navigator.appName; if (_app == 'Netscape') { document.write('<embed code="Applet1.class"', 'width="200"', 'height="200"', 'type="application/x-java-applet;version=1.5.0">'); } else if (_app == 'Microsoft Internet Explorer') { document.write('<OBJECT ', 'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"', 'width="200"', 'height="200">', '<PARAM name="code" value="Applet1.class">', '</OBJECT>'); } else { document.write('<p>Sorry, unsupported browser.</p>'); } </script> </html>You can use the HTML Converter tool to help with generating
object
andembed
tags for mixed environments.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.