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())