Determine whether client browser has java installed and can launch applets
Asked Answered
I

4

6

I am developing an .aspx page which will ultimately launch an applet after the user clicks on a button (I am using the <applet> tag). So, I would like to detect if java is enabled/installed on the user's browser.

I am using navigator.javaEnabled() method. However, even though this is working fine on IE7, it is returning inconsistent results on Firefox 3.0.12 (don't know about different browsers), sometimes saying that java is enabled (which it is), and then after launching the applet and coming back out of the applet to this page again, it will report false. If I close firefox and return to the applet launching page, navigator.javaEnabled() will report true again (correctly).

Is there anything that is determining this inconsistent behaviour or is navigator.javaEnabled() not the best way to do the java applet check?

Thanks in advance.

Indole answered 24/7, 2009 at 11:28 Comment(0)
H
11

Make in your applet a method

public boolean isRunning() { return true; }

Now create an applet:

<applet src=".../yourapplet.jar" id="someId">

And now wrap this code in some helper function

try {
  var x = document.getElementById('someId').isRunning()
  return x;
} catch(e) {
  return false;
}

Why this works? If applet runs it will return true. If applet doesn't run or Java is not supported you'll get an exception, so you'll get false.

Hokku answered 24/7, 2009 at 12:26 Comment(6)
Thanks Marcin for the answer. However if possible I would not like to run an applet for the test. Maybe I will resort to this method if I do not find another solution. The method I am using is working fine also on Google Chrome, but when I open the applet with Firefox, then close it and come back to the same page, the navigator.javaEnabled starts returning false. Very strange!Indole
The only way to be 100% certain that Java can run, is to call Java code. If you do not want to, then make it very visible to the user that if something does not happen within X seconds they most likely need to install Java.Ordovician
@Marcin, is this available for all browsers + JVM's or is it something that only works on certain combinations?Ordovician
Implemented as suggested. ThanksIndole
I have some issues with this solution in FF. It works great in other browsers, but with FF sometimes it doesn't and I have to ctr-f5 couple of times.Malvoisie
This should be working just fine in all browsers. That said, applet APIs are not really well supported these days and things often break...Hokku
L
1

You could also try using the object tag.

With it you can determine what version of java is installed and prompt the user to download it if it does not exist.

This is a sample object tag taken from an app that I work on, JRE complications required us to run on 1.4.2_03 for compatibility with other applications.

 <object classid="clsid:CAFEEFAC-0014-0002-0003-ABCDEFFEDCBA" id="MyApplet" 
 name="MyApplet" width="4" height="4" 
 codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2_03-windows-i586.cab#Version=1,4,2,03">

The classid specifies the version of Java you want to load, you can set this to a specific JRE, a specific family i.e. 1.4.X or whatever the latest version is.

The codebase controls where the user is directed if they do not meet what the classid is set to.

Note that if a client has 1.5 or higher installed you cannot reference an older JRE due to security constraints, You can override this via a registry setting in windows but I would not recommend it.

I believe the security is setup so you can only reference an older JRE in the same family. i.e. user has 1.6.0.10 you can reference 1.6.0.1 but cannot go to anything in 1.5.X Though I think I remember seeing a security dialog pop up after 1.6.0.11 where as before it would just default deny the request.

Louettalough answered 31/7, 2009 at 20:45 Comment(0)
M
1

There is also a commercial product called BrowserHawk.

http://www.cyscape.com/products/bhawk/workshop/detectjava.aspx?bhcp=1

Malvoisie answered 14/5, 2010 at 14:45 Comment(0)
Y
0

I think that this lib has the most comprehensive documentation and implementation that I could find and works pretty well

http://www.pinlady.net/PluginDetect/Java/

Yoo answered 28/12, 2012 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.