开发者

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


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜