Determine whether client browser has java installed and can launch applets

Timothy Mifsud picture Timothy Mifsud · Jul 24, 2009 · Viewed 8.4k times · Source

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.

Answer

Marcin picture Marcin · Jul 24, 2009

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.