基本上,我想找出在网页上检查用户的 JRE 版本的最佳方法。我有一个 JNLP 文件的链接,我只想在用户的 JRE 版本为 1.6 或更高版本时显示该文件。我一直在研究 deployJava JavaScript 代码 ( http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html ) 并让它在除 Safari 之外的所有浏览器中工作(通过使用 deployJava.versionCheck)。无论出于何种原因,Safari 都没有提供最新的 JRE 版本号——我通过显示 getJREs() 函数的值发现了这一点。我安装了 1.6.0_20,它显示在所有其他浏览器中,但 Safari 一直说目前只安装了 1.5.0。
我也尝试过使用 createWebStartLaunchButtonEx() 函数并将“1.6.0”指定为最低版本,但是当我单击按钮时没有任何反应(在任何浏览器中)。
有什么建议吗?
仅供引用:这是我的代码 --
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);
}
最佳答案
最好的办法可能是检查 navigator.plugins
数组。
这是一个适用于 Chrome/Firefox 的简单示例。据我所知,Internet Explorer 不提供对插件数组的访问。
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
关于javascript - 在浏览器中检查 JRE 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2761042/