Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question

9 Answers

up vote 9 down vote accepted

Check out the code in the Java Deployment Toolkit.

share|improve this answer
1  
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. – Dan Nov 19 '09 at 22:42
Update: This link is now broken. It looks like Adam Bellaire's link is going to be the one to use. – Ryan Kinal Apr 2 '12 at 20:02
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). – Julien Kronegg Sep 6 '12 at 13:04

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.

share|improve this answer
12  
Ironically, this page is now the first search result on Google for detect "java version" using javascript – kingjeffrey Apr 20 '10 at 16:31

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.

share|improve this answer
That does not give any information about the version (which the question is about). – Felix Kling Aug 6 '11 at 10:19
You're right, I didn't answer where I thought I was. Fixed my answer. – sarlak Aug 17 '11 at 7:11
This is just a duplicate of Rich Apodaca's previous answer, and Dan's comment on it applies. – T.J. Crowder Feb 17 '12 at 8:55
1  
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. – sarlak May 24 '12 at 14:05
1  
@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. – Patrick McElhaney Nov 14 '12 at 14:52
show 3 more comments

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

share|improve this 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.

share|improve this answer

Check out the solution here.

Works like a charm (at least on the local machine, yet I didn't test it on different environments).

share|improve this answer

Version of Java:

/**
 * @return NULL if not version found. Else return some things like: '1.6.0_31'
 */
var JavaVersion: function()
{
  var resutl = 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( (resutl = navigator.mimeTypes[i].type.match(/^application\/x-java-applet;jpi-version=(.*)$/)) !== null )
          return resutl[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.

share|improve this answer
JavaVersion does not work under MSIE since navigator.mimeTypes is always empty on this browser (tested on MSIE7) – Julien Kronegg Sep 4 '12 at 8:52

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

share|improve this 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.