Detect version of Java using JavaScript

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

Answers:

Answer

Check out the code in the Java Deployment Toolkit.

Answer

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.

Answer

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.

Answer

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

Answer

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.

Answer

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.

Answer

If you use Google Analytics, this post might be helpful (see the forum thread for more details).

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.