Referring to the previous table, note that only Windows 95, Windows NT 4.0, and Solaris operating environments with Netscape Navigator browsers pass all the tests. Because LiveConnect is used to get the OS version number and only Netscape Navigator browsers supports LiveConnect, a JavaScript that accesses LiveConnect will not be understood by Internet Explorer. To prevent this from causing a problem, you block out this piece of the script using the COMMENT tag since COMMENT is an Internet Explorer-specific comment tag. The text between the COMMENT tag is ignored by Internet Explorer but not by Netscape Navigator browsers. In addition, you must specify the script language as JavaScript1.1 to block this out if the browser is Netscape Navigator 2.
At this point, the above logic for Internet Explorer and Netscape Navigator browsers summarizes to a script that should look as follows:
<!-- The following code is specified at the beginning of the <BODY> tag. --> <SCRIPT LANGUAGE="JavaScript"><!-- var _info = navigator.userAgent; var _ns = false; var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); //--></SCRIPT> <COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!-- var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0 || _info.indexOf("Sun") > 0)); //--></SCRIPT></COMMENT> |
Remember that this block of JavaScript should be put at the top of the <BODY> of the HTML file. It is put at the top so that other JavaScripts can reference the variables _ie and _ns. This JavaScript is the same in all HTML files, and it is only needed once for each HTML body.
The second block of HTML tags are actually the corresponding OBJECT and EMBED tags that are mapped from the data in the APPLET tag. Note that JavaScript outputs the OBJECT tag when the browser is Internet Explorer running on the Windows 95, Windows 98 or Windows NT 4.0 operating environments. If the browser is the Netscape Navigator 4 browser on Windows 95, Windows 98, Windows NT 4.0, or Solaris operating environments, then JavaScript also outputs the EMBED tag, though with a slightly different syntax. Recall that the mechanism for detecting the browser and the platform has been described in the above section. (Tags <!-- and -> are used for comments in HTML.)
Original APPLET tag:
<APPLET code="XYZApp.class" codebase="html/" align="baseline" width="200" height="200"> <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz"> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! </APPLET> |
New style tag:
<SCRIPT LANGUAGE="JavaScript"><!-- if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="200" height="200" align="baseline" codebase="http://java.sun.com/jpi/jinstall-14-win32.cab#Version=1,4,0,mn"> <NOEMBED><XMP> '); else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.4" width="200" height="200" align="baseline" code="XYZApp.class" codebase="html/" model="models/HyaluronicAcid.xyz" pluginspage="http://java.sun.com/jpi/plugin-install.html"> <NOEMBED><XMP>'); //--></SCRIPT> <APPLET code="XYZApp.class" codebase="html/" align="baseline" width="200" height="200"></XMP> <PARAM NAME="java_code" VALUE="XYZApp.class"> <PARAM NAME="java_codebase" VALUE="html/"> <PARAM NAME="java_type" VALUE="application/x-java-applet;version=1.4"> <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz"> LUE="models/HyaluronicAcid.xyz"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! </APPLET></NOEMBED></EMBED> </OBJECT> |
Note that the original APPLET tag is also mapped in the new Java Plug-in tag. This is done because Java Plug-in is intended to be used only on supported platforms. Leaving the APPLET tag in the script ensures that browsers that do not support Java Plug-in, or browsers that do not support JavaScript can gracefully handle the applet using the default JVM. HotJava Browser, Internet Explorer, and Netscape Navigator browsers on non-Java Plug-in supported platforms, or browsers without JavaScript support, read the above tags as follows:
<APPLET code="XYZApp.class" codebase="html/" align="baseline" width="200" height="200"></XMP> <PARAM NAME="java_code" VALUE="XYZApp.class"> <PARAM NAME="java_codebase" VALUE="html/"> <PPARAM NAME="model" VALUE="models/HyaluronicAcid.xyz"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! <PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.4"> </APPLET></NOEMBED></EMBED></OBJECT> |
These browsers ignore the tags </XMP>, </OBJECT>, </EMBED>, and </NOEMBED> as well because there is no corresponding <XMP>,<OBJECT>, <EMBED>, and <NOEMBED> tags. Because Java Plug-in is targeted for features in the Java 2 SDK, Standard Edition v 1.4 or future releases, those browsers without full Java 2 SDK 1.4 support and who do not support Java Plug-in will display the message "No Java 2 SDK, Standard Edition v 1.4 support for APPLET".
Unlike the previous examples, the mapped PARAM names contain java_code, java_codebase, and java_type instead of code, codebase, and type. This is necessary because specifying code and codebase in the <PARAM> inside the <APPLET> and </APPLET> tag causes problems in some browsers.
Internet Explorer on Windows 95, Windows 98 or Windows NT 4.0 reads the tags as follows:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="200" height="200" align="baseline" codebase="http://java.sun.com/jpi/jinstall-14-win32.cab#Version=1,4,0,mn"> <NOEMBED><XMP> <APPLET code="XYZApp.class" codebase="html/" align="baseline" width="200" height="200"></XMP> <PARAM NAME="java_code" VALUE="XYZApp.class"> <PARAM NAME="java_codebase" VALUE="html/"> <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz"> <PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.4"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! </APPLET></NOEMBED></EMBED> </OBJECT> |
Be careful when you use the <XMP> tag. Because Internet Explorer renders the <OBJECT> tag, you must disable the <APPLET> tag. If not disabled, two applets will simultaneously show up in the browser--one applet will be running in Microsoft's JVM, and the other will be running in Sun's JVM using Java Plug-in. The <XMP> tag provides a solution. The <XMP> and </XMP> tags basically transform any HTML tag that occurs between them into a stream of static text. In the above example, the <XMP> and </XMP> tags cause the browser to treat the <APPLET> tag as static text instead of an HTML tag. Because the browser ignores any static text between the <OBJECT> tag and the <PARAM> tag, the above tags actually become:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="200" height="200" align="baseline" codebase="http://java.sun.com/jpi/jinstall-14-win32.cab#Version=1,4,0,mn"> <PARAM NAME="java_code" VALUE="XYZApp.class"> <PARAM NAME="java_codebase" VALUE="html/"> <PARAM NAME="java_type" VALUE="application/x-java-applet;version=1.4"> <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! </OBJECT> |
This is identical to the OBJECT tag example outlined above. Note that the <OBJECT> tag ignores the <NOEMBED>, </NOEMBED>, and <EMBED> tags.
Netscape Navigator 4 on Windows 95, Windows 98 or Windows NT 4.0 operating environments reads tags as follows:
<EMBED type="application/x-java-applet;jpi-version=1.4" width="200" height="200" align="baseline" code="XYZApp.class" codebase="html/" model="models/HyaluronicAcid.xyz" pluginspage="http://java.sun.com/jpi/plugin-install.html"> <NOEMBED><XMP> <APPLET code="XYZApp.class" codebase="html/" align="baseline" width="200" height="200"></XMP> <PARAM NAME="java_code" VALUE="XYZApp.class"> <PARAM NAME="java_codebase" VALUE="html/"> <PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.4"> <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! </APPLET></NOEMBED></EMBED></OBJECT> |
Note that the <XMP> tag is used again in the <EMBED> tag to also disable the <APPLET> tag. The <EMBED> tag ignores the <PARAM> and </OBJECT> tags as well. In effect, the above tags actually become:
<EMBED type="application/x-java-applet;jpi-version=1.4" width="200" height="200" align="baseline" code="XYZApp.class" codebase="html/" model="models/HyaluronicAcid.xyz" pluginspage="http://java.sun.com/jpi/plugin-install.html"> <NOEMBED> No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! </NOEMBED> </EMBED> |
This is identical to the EMBED tag example outlined above.
You can use the combined OBJECT-EMBED-JavaScript tag to activate Java Plug-in in the right browser on the right platform. This combined tag is complicated and it should be used only if your HTML page is browsed by users in a heterogeneous environment.