Brian
Brian

Reputation: 1896

Checking JRE version inside browser

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);
}

Upvotes: 1

Views: 5838

Answers (2)

aioobe
aioobe

Reputation: 421280

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

How to check JRE version prior to launch?

Upvotes: 1

Matt
Matt

Reputation: 44078

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

Upvotes: 1

Related Questions