Try Out The Java Platform Detection Code
David Herron: Recently we made Java SE 6 update 10 available for beta testing. Beta testing is a period in product release cycles where testing is taken to people outside the product team, and those "external" testers bang on it with their applications and let the product team know what's wrong (or not).
I find the following snippet Java platform detection code interesting:
<script src="http://java.com/js/deployJava.js"></script>
<script language="JavaScript">function detectJRE() {
var list = deployJava.getJREs();
var result = "";
if (list.length == 0) {
alert ('No Detectable Java Platforms are Installed');
} else {
result = list[0];
for (var i=1; i < list.length; i++) {
result += ", " + list[i];
}
alert("You have the following Java Platform(s) installed: \n" + result);
}
}</script>
And you can try it out here:
Unfortunately, here's what I get on my home computer:
This is on a Debian GNU/Linux amd64 4.0 platform. We haven't had the Java plugin or Java Web Start for quite some time now. It looks like we'll get the plugin in early 2009, according to Bug ID: 4802695.
[Update] The comment by Anonymous made me curious. So I tried out the code on my Mac OS X 10.3 machine. Here are the results for Safari:
and for Firefox
The result from Safari is correct as the highest version of Java available for Panther is 1.4.2.
Just for completeness here are the results on the XP laptop, for IE7
for Firefox 3 Beta 5
and for Safari
Here, both IE7 and Firefox 3 Beta 5 detected the installed JREs accurately. The script did not detect any JREs from Safari even though my Safari "Installed Plug-ins" page showed both the "Java(TM) Platform SE 6 U10" and the "Apple Java Plug-In" as installed plugins.
Such is the wonderful world of JavaScript.