Solaris Java Plug-in User's Guide

Java Plug-in Anywhere

In an Internet/intranet environment, an HTML page is likely to be seen by browsers on different platforms. You should activate Java Plug-in only on the right browser and platform combination. Otherwise, you should use the browser's default JVM. You can achieve this using the following Java Plug-in tag:

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:

The following is an example of an equivalent Java Plug-in tag. This example includes comments.


<!-- 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>

<!-- The following code is repeated for each APPLET 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;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>');
//--></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;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>

<!--
      <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>
-->

Although this tag seems complicated compared to the old APPLET tag, it is not. Most of the Java Plug-in tag is the same regardless of the applet used. For the majority of cases, a webmaster can copy and paste the Java Plug-in tag.

The first block of the script extracts the browser and platform. You must determine the browser and platform on which the applet is running. You do this by using JavaScriptTM to extract first the browser name, then the platform. This is done once per HTML document.

The second block of the script replaces the APPLET tag. You must replace each APPLET tag with a similar block of code. The script replaces the APPLET tag with either an EMBED tag or OBJECT tag, depending on the browser. You use the OBJECT tag for Internet Explorer and the EMBED tag for Netscape Navigator browsers. Finally, the original APPLET tag is included as a comment at the end. It is always a good idea to keep the original APPLET tag in case you want to remove the Java Plug-in invocation.

The first JavaScript establishes the browser and the platform on which the browser is running. You must do this because, currently, Java Plug-in supports only Microsoft Windows platforms and the Solaris operating environment. Note that Windows NT 3.51 is the only Win32 platform that Java Plug-in does not support. Java Plug-in should be invoked only on the supported browser and platform. The script sets the variable _ie to true if the browser is Internet Explorer. It sets the variable _ns to true if the browser is a Netscape browser. (Note that all variable names in the JavaScript start with "_". This is done to avoid conflicting with other JavaScript variables in the same page.)

To detect the right browser, the JavaScript evaluates three strings that are within the JavaScript's Navigator object: userAgent, appVersion, and appName. These strings contain information about the browser and the platform. By looking at some examples of the string userAgent, you can see how to evaluate userAgent and use it to determine the browser. The following are some examples of the userAgent string for different platforms as it appears in Internet Explorer. In the table, IE stands for Internet Explorer.

Platform and Browser 

JavaScript's Navigator.userAgent string

Windows 2000 w/IE 5.0 

"Mozilla/4.0 (compatible; MSIE 5.01; Window NT5.0) 

Windows NT 4.0 w/ IE 4.0 

"Mozilla/4.0 (compatible; MSIE 4.0; Windows NT)" “ 

Windows 95 w/IE 4.0 

"Mozilla/4.0 (compatible; MSIE 4.0; Windows 95)“ 

Windows NT 3.51 w/ IE 4.0 

"Mozilla/4.0 (compatible; MSIE 4.0; Windows 3.1)“ 

Windows 3.1 w/IE 4.0 

"Mozilla/4.0 (compatible; MSIE 4.0; Windows 3.1)“ 

Windows NT 4.0 w/Navigator 4.04 

"Mozilla/4.04 [en] (WinNT; I)“ 

Windows NT 3.51 w/Navigator 4.04 

"Mozilla/4.04 [en] (WinNT; I)“ 

Windows 95 w/Navigator 4.03 

"Mozilla/4.03 [en] (Win95; I)“ 

Solaris 2.6 w/Navigator 4.02 

"Mozilla/4.02 [en] (X11; l; SunOS 5.6 sun4u) 

Note that in each case the substring "MSIE" is always in the userAgent string in Internet Explorer. Also, the userAgent string in Internet Explorer under Windows 3.1 and Windows 3.51 would contain the substring "Windows 3.1" because Internet Explorer in these platforms is 16-bit. While Internet Explorer 4 is also available on Macintosh and the Solaris operating environment, in these versions the userAgent string does not contain the substring "Win". In addition, Internet Explorer on Windows CE does not support JavaScript. This can be summarized as follows:

userAgent string / Browser

contains “MSIE” 

contains “Win” 

does not contain “Windows 3.1” 

Windows 3.1 w/ IE 4 

 

Windows NT 3.51 w/ IE 4 

 

Windows 95 w/IE 4 

Windows NT 4.0 w/ IE 4 

Windows CE w/ IE 

 

 

 

Mac w/ IE 

 

UNIX w/ IE 

 

Other browsers on any platform 

 

 

The above table shows that only Windows 95 and Windows NT 4.0 with Internet Explorer can pass the Java Plug-in browser and platform requirements. However, this logic makes no assumptions about future releases of Internet Explorer or future releases of Microsoft Windows with Internet Explorer. As long as the userAgent string contains "MSIE" and "Win", the above code should work in future releases of Internet Explorer on Win32.

The above logic summarizes into the following:


<SCRIPT LANGUAGE="JavaScript">
          var _info = navigator.userAgent;
          var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0
                  && _info.indexOf("Windows 3.1") < 0);
//--></SCRIPT>

It is harder to detect Navigator on the right platform. Using just JavaScript, there is no way to determine if the browser is running on the Windows NT 3.51 or Windows NT 4.0 operating platform. (Refer to the above table and examine the userAgent string. Notice that the userAgent strings in Windows NT 3.51 and Windows NT 4.0 operating platforms are the same in Netscape Navigator browsers.) It is important to make this distinction because Java Plug-in supports only the Windows NT 4.0 operating platform. To run Java Plug-in on the right platform, you must use LiveConnect in Netscape Navigator browsers to determine the OS version number. This can be summarized as follows:

Testing logic / Browser 

appName contains “Netscape” 

userAgent contains "Win" 

userAgent does not contain "Win16" 

os.version does not contain 3.5 

userAgent contains "Sun" 

Windows 3.1 w/ Netscape 4 

 

 

Windows NT 3.51 w/ Netscape 4 

 

 

Windows 95 w/ Netscape 4 

 

Windows NT 4.0 w/ NS 4 

 

NS on Solaris 

 

 

 

IE on Solaris 

 

 

 

 

Netscape on other platform 

 

Depends on OS 

 

IE on other platform 

 

 

 

Other browsers on any platform 

 

 

 

 

 

The above logic translates into the following code:


<SCRIPT LANGUAGE="JavaScript">
         var _info = navigator.userAgent; var _ns = false;
//--></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>

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.