frequently ask ? : Computers : Programming : Languages : JavaScript : Applets/Java

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 37 people (62%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I check whether the Sun Java Plugin is installed and which version of the JKD/JRE is supports?

Jan 26th, 2001 05:19
Martin Honnen,


NN4+ and Opera 5 (maybe earlier versions too) support the 
  navigator.mimeTypes
and the 
  navigator.plugins
which allow you to check for a certain mime type support or a certain 
plugin, as shown in
  http://www.faqts.com/knowledge_base/view.phtml/aid/1986/fid/125
So you check for
  var appletMimeType = 
    navigator.mimeTypes['application/x-java-applet'];
to find the mime type which is associated with the Java plugin, then 
you check for a plugin that supports it
  if (appletMimeType.enabledPlugin)
    alert(appletMimeType.enabledPlugin.description);
This shows something like
  Java Plug-in 1.2.2 for Netscape Navigator with JDK/JRE 1.2.2
from which you can extract the version number for example with the 
following regular expression
  var re = /JRE (\d\.\d(\.\d))/;
The following function does all the checks and extracting for you and 
returns 
  null
if the mime type or plugin or the version number is not found and the 
version number in the form
  d.d.d
otherwise:
function JREVersion () {
  var appletMimeType = navigator.mimeTypes['application/x-java-applet'];
  if (!appletMimeType || !appletMimeType.enabledPlugin)
    return null;
  var re = /JRE (\d\.\d(\.\d))/
  var match = re.exec(appletMimeType.enabledPlugin.description);
  if (!match)
    return null
  else {
    var jreVersion = match[1];
    return jreVersion;
  }
}
// example:
alert(JREVersion())