使用 JavaScript 检测 Java 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/440160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:38:23  来源:igfitidea点击:

Detect version of Java using JavaScript

javajavascriptxhtml

提问by

Is there a reliable way of detecting what version of Java is installed on the client's machine using JavaScript?

是否有一种可靠的方法可以使用 JavaScript 检测客户端计算机上安装的 Java 版本?

采纳答案by Rich Apodaca

Check out the code in the Java Deployment Toolkit.

查看Java 部署工具包中的代码。

回答by Adam Bellaire

Googling for

谷歌搜索

detect "java version" using javascript

detect "java version" using javascript

yields a couple of results, this onelooks like it might be useful. In essence, it tries to load a Java applet and then JavaScript asks the applet.

产生了几个结果,这个看起来可能有用。本质上,它尝试加载 Java 小程序,然后 JavaScript 询问小程序。

回答by Sarel Botha

You can use the PluginDetect library from here: http://www.pinlady.net/PluginDetect/

您可以从这里使用 PluginDetect 库:http: //www.pinlady.net/PluginDetect/

回答by Michael Myers

If you use Google Analytics, this postmight be helpful (see the forum threadfor more details).

如果您使用 Google Analytics,这篇文章可能会有所帮助(有关更多详细信息,请参阅论坛主题)。

回答by sarlak

According to the fact that we're finding this page with google, just to help the next guys finding this.

根据我们正在用谷歌找到这个页面的事实,只是为了帮助下一个人找到这个。

Is Java installed?

安装Java了吗?

navigator.javaEnabled()

http://www.w3schools.com/jsref/met_nav_javaenabled.asp

http://www.w3schools.com/jsref/met_nav_javaenabled.asp

Which version of Java is installed?

安装了哪个版本的 Java?

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
var versions = deployJava.getJREs();
</script>

http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit

http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit

It's the best way I found to find the version of Java with JavaScript, but use it carefully because its version detection is really os/browser dependent, and on old browser version or on recent browser with old Java installed, it'll not work as expected. Take the time to do real tests before to use it in production.

这是我发现使用 JavaScript 查找 Java 版本的最佳方法,但请谨慎使用它,因为它的版本检测确实依赖于操作系统/浏览器,并且在旧浏览器版本或安装了旧 Java 的最新浏览器上,它无法正常工作预期的。在生产中使用它之前花时间做真正的测试。

回答by user942973

The detection logic does not work in IE32 on Windows7-64. It could not detect the java version it installed earlier.

检测逻辑在 Windows7-64 上的 IE32 中不起作用。它无法检测到它之前安装的 Java 版本。

Well, after further reading, the Java Deployment Toolkit on Windows uses ActiveX classid which may pose your app to hackers (see http://www.kb.cert.org/vuls/id/886582). I am out.

好吧,进一步阅读后,Windows 上的 Java 部署工具包使用 ActiveX classid,这可能会将您的应用程序暴露给黑客(请参阅http://www.kb.cert.org/vuls/id/886582)。我出去了。

回答by ImmortalPC

Version of Java:

Java版本:

/**
 * @return NULL if not version found. Else return some things like: '1.6.0_31'
 */
var JavaVersion: function()
{
  var result = null;
  // Walk through the full list of mime types.
  for( var i=0,size=navigator.mimeTypes.length; i<size; i++ )
  {
      // The jpi-version is the plug-in version.  This is the best
      // version to use.
      if( (result = navigator.mimeTypes[i].type.match(/^application\/x-java-applet;jpi-version=(.*)$/)) !== null )
          return result[1];
  }
  return null;
}
/**
 * @return NULL if not version found. Else return some things like: '1.6.0_31'
 */
var JavaVersion: function()
{
  var result = null;
  // Walk through the full list of mime types.
  for( var i=0,size=navigator.mimeTypes.length; i<size; i++ )
  {
      // The jpi-version is the plug-in version.  This is the best
      // version to use.
      if( (result = navigator.mimeTypes[i].type.match(/^application\/x-java-applet;jpi-version=(.*)$/)) !== null )
          return result[1];
  }
  return null;
}

Is Java and is Java enable:

是 Java 还是 Java 启用:

var IsJava: function()
{
  return typeof(navigator.javaEnabled) !== 'undefined' && navigator.javaEnabled();
}
var IsJava: function()
{
  return typeof(navigator.javaEnabled) !== 'undefined' && navigator.javaEnabled();
}

These functions works on Opera, Firefox, Chrome. I havn't IE.

这些功能适用于 Opera、Firefox、Chrome。我没有 IE。

回答by WilliamK

I find that the JavaScript solution provided by the Java Deployment Toolkit gives an error... "deployJava.do_initialize is not a function".

我发现 Java 部署工具包提供的 JavaScript 解决方案给出了一个错误...“deployJava.do_initialize is not a function”。

One solution that I have used extensively for many years that does work in all browsers is the Java Version Display Applet. Unfortunately the original author's site seems to have disappeared, but you can download a copy of the Java Version Display Applethere.

我多年来广泛使用的一种在所有浏览器中都有效的解决方案是Java 版本显示小程序。不幸的是,原作者的站点似乎已经消失了,但您可以在此处下载Java 版本显示小程序的副本。