Below I’m pasting in some code to determine whether or not the browser has a specified version of the plugin or above.
My intended application is to use this transparently, displaying the ‘real’ applet in the body if the plugin meets the specified requirement and either using document.setLocation or popping up a new window to navigate users to the “Get Java” page if not.
I’m wondering if some of you would mind testing this out in whatever browsers you have handy. I’m not particularly concerned with supporting browsers more than a generation or two ago, but correct execution on most/all current browsers is important IMO.
I have dialup access, so I need to download some other browsers anyway but it will take a while. It does work on IE 6.
detection.html
<HTML>
<HEAD>
<TITLE>Detect Java Plugin</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function checkJavaPlugin() {
var minimumVersion = "1.4.1";
var applet = document.applets["DetectPluginApplet"];
if(applet == null) {
alert("You do not have support for Java. Please download a plugin.");
}
var supported = applet.meetsRequirements(minimumVersion);
if(supported) {
document.write("Your browser supports the minimum requirement of\n" +
minimumVersion);
}
else document.write("Your browser does not meet the requirement of\n" +
minimumVersion + ". At this point a call to document.setLocation() would redirect you to the
\"Get Java\" page.");
}
</SCRIPT>
<BODY onLoad="checkJavaPlugin()">
<APPLET NAME="DetectPluginApplet" CODE="DetectPlugin.class" WIDTH=0 HEIGHT=0>
</APPLET>
</BODY>
</HTML>
DetectPlugin.java
public class DetectPlugin extends java.applet.Applet {
public boolean meetsRequirements(String minimumVersion){
String version = System.getProperty("java.version");
return version.compareTo(minimumVersion) >= 0;
}
}
Also, any tips on improving this (especially if it turns out that it is not cross-browser-compatible) are very welcome!