15

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

1
  • Check out the solution here. Works like a charm (at least on the local machine, yet I didn't test it on different environments). Commented Jul 20, 2010 at 17:45

7 Answers 7

13

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.

Sign up to request clarification or add additional context in comments.

9 Comments

That does not give any information about the version (which the question is about).
You're right, I didn't answer where I thought I was. Fixed my answer.
This is just a duplicate of Rich Apodaca's previous answer, and Dan's comment on it applies.
Yeah ... just make it more explicite for thoses who doesn't understand everything on the page he gave, or if ever the link dies ... or just to save some time to the next guys who find this page via Google. I didn't mean to steal one's good answer.
@T.J.Crowder Top 0.02% user gets schooled by a first time answerer in Stack Overflow's philosophy of making the internet better. That's something you don't see every day.
|
12

Check out the code in the Java Deployment Toolkit.

3 Comments

In case someone comes across this again, note the toolkit has a major flaw: it returns the highest version of Java that is installed on the machine, not the highest version that is actually runnable (in IE, at any rate). Specifically, if you have both a Sun JRE and MSJVM installed, the toolkit will report the Sun JRE version even if it's disabled and the browser will actually run MSJVM. Adam Bellaire's link below seems more reliable, albeit less "clean" because it requires running an actual applet.
Update: This link is now broken. It looks like Adam Bellaire's link is going to be the one to use.
Moreover, this method makes the MSIE gold security warning bar to be popped up under MSIE7 with Sun JDK before 1.6.0_2 (with Middle-High security settings). See pinlady.net/PluginDetect for a version which does not raise security warnings (and is maintained).
5

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.

1 Comment

Ironically, this page is now the first search result on Google for detect "java version" using javascript
4

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

Comments

4

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.

2 Comments

JavaVersion does not work under MSIE since navigator.mimeTypes is always empty on this browser (tested on MSIE7)
navigator.mimeTypes appears to be present in IE11
1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.