June 25, 2007

Detecting Java WebStart on Internet Explorer

So, I haven't posted very much recently, not for any particularly important reason, but simply because I've been doing other things with my free time. The next few days I have very little to do, however (I'm on vacation back in Washington state), and so I'm hoping to get a few things posted that I've been meaning to post. The first of these is a little off the usual topic of this blog, but I think it will be of interest if not to my usual readers, at least to those who find it on google.

At work last week, I discovered a technique for detecting the presence of Java WebStart on MS Internet Explorer 6 and 7 using JScript and ActiveX. My fellow web developers will know that Internet Explorer is not compatible or compliant with anything. It ignores essentially all standards, and the useful and secure techniques for doing things like detecting plugins on other browsers generally won't work. Meanwhile, the things that do work on Internet Explorer don't work anywhere else. The following code snippet, however, successfully detects the presence of Java WebStart on (at least) Firefox for Windows, Gecko (Mozilla)-based Linux browsers, Safari for Mac, and Internet Explorer 6 and 7 for Windows. It doesn't seem to work with the Linux browser Konqueror. On IE6, it works without a hitch on default security settings. IE7 gives the "active content" warning and until permission is given WebStart will not be detected. Here it is:


function testWebstart(){
var webstart = 'unknown';
//standards-compliant browsers
if(navigator.mimeTypes && navigator.mimeTypes.length > 1){
if(navigator.mimeTypes['application/x-java-jnlp-file']){
webstart = true;
}else{
webstart = false;
}
}
//Microsoft Browsers
if(webstart == 'unknown'){
try{
var test = new ActiveXObject("JavaWebStart.isInstalled");
webstart = true;
}catch(e){
webstart = false;
}
}
return webstart;
}

The function returns the string 'unknown' if the status cannot be determined. Otherwise, it returns a boolean indicating whether WebStart is installed. I don't know what, if anything, the ActiveX object created by the code can be used for; I just found it by looking through the Windows registry and decided to give it a try.

Posted by Kenny at June 25, 2007 11:33 AM
Trackbacks
TrackBack URL for this entry: http://blog.kennypearce.net/admin/mt-tb.cgi/342

Post a comment





Return to blog.kennypearce.net