Detect version of Java using JavaScript

2019-01-11 13:53发布

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

8条回答
我想做一个坏孩纸
2楼-- · 2019-01-11 14:33

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

Is Java installed?

navigator.javaEnabled()

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

Which version of Java is installed?

<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

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.

查看更多
Luminary・发光体
3楼-- · 2019-01-11 14:40

Version of 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;
}

Is Java and is Java enable:

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

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

查看更多
对你真心纯属浪费
4楼-- · 2019-01-11 14:41

Googling for

detect "java version" using javascript

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

查看更多
聊天终结者
5楼-- · 2019-01-11 14:41

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

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.

查看更多
6楼-- · 2019-01-11 14:44

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

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-01-11 14:44

I find that the JavaScript solution provided by the Java Deployment Toolkit gives an error... "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 Applet here.

查看更多
登录 后发表回答