John Doe
John Doe

Reputation:

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?

Upvotes: 15

Views: 36690

Answers (7)

ImmortalPC
ImmortalPC

Reputation: 1690

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.

Upvotes: 4

sarlak
sarlak

Reputation: 151

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.

Upvotes: 13

Rich Apodaca
Rich Apodaca

Reputation: 29014

Check out the code in the Java Deployment Toolkit.

Upvotes: 12

user942973
user942973

Reputation: 11

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.

Upvotes: 1

Michael Myers
Michael Myers

Reputation: 192035

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

Upvotes: 0

Sarel Botha
Sarel Botha

Reputation: 12710

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

Upvotes: 4

Adam Bellaire
Adam Bellaire

Reputation: 110519

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.

Upvotes: 5

Related Questions