This is as days pass by, by Stuart Langridge

And this is iTheora and Java support detection, written , and concerning JavaScript and the DOM, LazyWeb, Web, and Software

Interesting project: iTheora, a PHP script handling in-browser display of Ogg Theora video files, using the Flumotion Cortado Java applet. The site's originally in French but has also been translated into English by Bruno (nice one Bruno!). I'd like to do this client-side with JavaScript. The big issue I find with Cortado, and indeed all Java applets, is: Java takes so long to start up. What I'd like to do is only load the Java applet if someone asks to see the video, and not show it at all if they don't have Java installed. The problem is: how do you detect whether the punter can display Java applets, without starting Java? As far as I can tell, it isn't possible. I've seen a few attempts at it, but none of them work across browsers. JavaScript people: how do you detect Java support without starting Java? I'm quite happy to write the script to do it if I can work out how, but all my experimentation and research have not led me to a solution. Lazyweb: help me out!

Comments

ppk

if (navigator.javaEnabled())

should do the trick. I'm not totally sure it works in all browsers, though, and it merely states that Java is available, not that it is already running.

sil

ppk: if it were that easy I'd have done that already. :) IE6 *sometimes* will return false for navigator.javaEnabled() if you're using a non-Microsoft Java. It's also, apparently, broken in lots of versions of Netscape/Mac (which I can't test).

rgm

I understand you're trying to detect java without actually launching a JVM -- that's hard. When I solved this problem I did not have that requirement, so I load a 1.0-compatible applet with a public getVersion() method that returns System.getProperty("java.version") to query the JVM version. I also load both of these scripts (one is a .vbs just for IE, the .js for Firefox) on the page to check from script:

These scripts need tweaking to apply to your situation, in my case I was sniffing for 1.4 support.

---- from checkjava.js (firefox /netscape compatible) ------------

var supports14 = false;

function checkJava() {

// Firefox

if ( navigator.plugins && navigator.plugins.length > 0 ) {

nps = navigator.plugins;

for ( i = 0; i = 0 ) {

idx = mtype.type.indexOf("version=");

if ( idx > 0 ) {

version = mtype.type.substr( idx + 8, 3 );

if ( version == "1.4" ) { supports14 = true; break; }

}

}

}

}

}

}

---------- from checkjava.vbs (for IE) -----------------------------

'* Note that is_ie has been previously defined, prolly based on User-Agent string

on error resume next

If is_ie Then

If Not(IsObject(CreateObject("JavaWebStart.isInstalled"))) Then

javawsInstalled = 0

Else

javawsInstalled = 1

End If

If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.4.2.0"))) Then

javaws142Installed = 0

Else

javaws142Installed = 1

End If

If Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.5.0.0"))) Then

javaws150Installed = 0

Else

javaws150Installed = 1

End If

supports14 = javaws150Installed Or javaws142Installed

End If

'* needs updating for java 1.6

Eric Gerds

"What I’d like to do is only load the Java applet if someone asks to see the video"

How about you do Java detection only after someone asks to see the video? If Java is present, the Java detection starts up Java...but so what since you are going to be using Java anyway to display the video.

If Java is not present, no big deal. No startup delay since it is not installed.

Also it is usually IE that starts up Java during detection, not other browsers.

sil

Eric: if I only detect Java after someone tries to watch the video, then anyone without Java installed will say "yes, show me the video!" and the site will say "well, you can't, unlucky". That's really annoying; we shouldn't offer people a chance to do something that we can know that they won't be able to do.

Eric Gerds

I am curious. have you tried Sun Java 1.6 lately? It takes ALOT longer to start up than Sun Java 1.5. So much so, that I consider it unbelievable - sometimes nearly 10 seconds or more. It's really, really bad.

If you put Java detection on your page, it looks to the user like your page never loads. Many people don't have the patience for that, and will just leave your site.

You might be better off using Flash for displaying videos, as opposed to Java.

So the question is what is more annoying. Having your home page appear that it doesn't ever load (in reality a bad delay due to Java startup), or having a message popup saying 'sorry' when they click on a link to see your video.

It is my conclusion that there is no way in IE to detect Java without starting it up. But that statement must be qualified.

Prior to IE 7, you could look for certain ActiveX objects like "JavaWebStart.isInstalled"

which would not start Java, and would tell you the Java Family version present.

However, IE 7 has made plugin detection for Java (and QuickTime) alot more difficult. All ActiveX objects are deactivated by default, meaning they won't work the first time unless the user clicks on that yellow security popup the first time.

There are only a small number of pre-approved ActiveX controls that never give that popup.

So, for IE

For IE 7, the best I can do is try to detect some minimum version of Java. If Java is min version, then Java starts up.

I have spent the last year trying to find ways to detect Java. And there are no simple answers.

Eric Gerds

I messed up that last part. What I wanted to say was I can detect if Java is some minimum version. If it is, Java starts. If it is not a minimum version, then it won't start up.

sil

Eric: that's why I asked for a way of detecting Java without starting Java. I can't use Flash because it doesn't play Ogg Theora. If there really is no way of detecting Java without starting it then, well, I lose. :)

Eric Gerds

If I ever find a way, I'll let you know. But for the time being there does not appear to be any practical answer. I have noticed that every new major version of Sun Java takes progressively longer to start up. They've done a pretty bad job with that.

Here are a few comments/tests regarding Java that I have so far:

http://www.pinlady.net/test/PluginDetect.htm

Eric Gerds

Just to update, the url for Java detection is now here:

http://www.pinlady.net/PluginDetect/JavaDetect.htm

It turns out that for the newer versions of Sun Java, one can detect the JRE very quickly in Internet Explorer without starting up the full JRE.

Older JRE versions are a different story.

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.