views:

200

answers:

2

Basically, I'm wanting to figure out the best way to check the user's JRE version on a web page. I have a link to a JNLP file that I only want to display if the user's JRE version is 1.6 or greater. I've been playing around with the deployJava JavaScript code (http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html) and have gotten it to work in every browser but Safari (by using deployJava.versionCheck). For whatever reason, Safari doesn't give the most updated JRE version number - I found this out by displaying the value of the getJREs() function. I have 1.6.0_20 installed, which is displayed in every other browser, but Safari keeps saying that only 1.5.0 is currently installed.

I've also tried using the createWebStartLaunchButtonEx() function and specifying '1.6.0' as the minimum version, but when I click the button nothing happens (in any browser).

Any suggestions?

FYI: Here's my code --

if (deployJava.versionCheck('1.6+')) {
    var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
    var url = dir + "tmaj.jnlp";
    deployJava.createWebStartLaunchButton(url, '1.6.0');
} else {
    var noticeText = document.createTextNode("In order to use TMAJ, you must visit the following link to download the latest version of Java:");
    document.getElementById('jreNotice').appendChild(noticeText);

    var link = document.createElement('a');
    link.setAttribute('href', 'http://www.java.com/en/download/index.jsp');
    var linkText = document.createTextNode("Download Latest Version of Java");
    link.appendChild(linkText);
    document.getElementById('jreDownloadLink').appendChild(link);
}
+1  A: 

Probably the best bet would be to check the navigator.plugins array.

Here is a quick example that works in Chrome/Firefox. As far as I know, Internet Explorer does not provide access to the plugins array.

function getJavaVersion() {
    var j, matches;
    for (j = 0;j < navigator.plugins.length;j += 1) {
        matches = navigator.plugins[j].description.match(/Java [^\d]+(\d+\.?\d*\.?\d*_?\d*)/i);
        if (matches !== null) {
            return matches[1];
        }
    }
    return null;
};

console.log(getJavaVersion()); // => 1.6.0_16
Matt
That would be to gamble a bit, wouldn't it? I mean, that checks the java version used by the browser plugin for applets, right? and not necessarily the default JRE-version used when running stand-alone / webstart applications?
aioobe
@aioobe - The entire goal is a gamble because it's possible the user has multiple JREs. The Java Control Panel will let you set different JREs for applets and webstart applications. So having the browser check it will never be a perfect science. The OP should just rely on `JNLP`'s minimum JRE attribute.
Matt
+1  A: 

Not sure if it helps you but you can specify the minimum jre version as a clause in the jnlp file. Webstart will not launch your app if the requirement is not met.

See the tag.

Also, have a look at

http://stackoverflow.com/questions/222187/how-to-check-jre-version-prior-to-launch

aioobe