Two of the new reports I hope to provide with the new W3Counter are whether a site's visitors have Flash and Java installed. Since different browsers, and different versions of browsers, make plugin information available in different ways, this is proving more challenging than expected. I have a first attempt at detection of Flash and Java plugins running now, but I'm not sure if I can trust the data I'm getting back yet.
Here's the problem:
- Mozilla-based browsers make available an array called navigator.plugins which contains the list of plugins in the browser.
- Internet Explorer in Windows has this array, but it's always empty.
- Internet Explorer 5 on Mac has the array and fills it like Mozilla.
- Opera on Mac and Linux, and iCab, don't have this array, but do potentially have the Flash mime-type listed in a mimeTypes array.
- With Internet Explorer 4+, you can detect Flash by instantiating a Flash object with VBScript, but you'll produce an error message when Flash isn't there.
- Internet Explorer 3 and 4 on Mac don't support VBScript (or the plugins array).
- Java can also be tested for with a navigator.javaEnabled() method, which kinda sorta works in most browsers, but is broken in at least most versions of Netscape for Mac, and sometimes returns false in IE6 on WinXP if a non-Microsoft Java plugin is installed (such as one directly from Sun).
This is the code I'm using now; I haven't added a search through the mime types yet which should improve accuracy:
-
flash_versions = 10;
-
flash_installed = 0;
-
flash_version = '0.0';
-
java_installed = 0;
-
-
// Netscape style plugin detection
-
if (navigator.plugins && navigator.plugins.length) {
-
for (x = 0; x <navigator.plugins.length; x++) {
-
if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
-
flash_version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
-
flash_installed = 1;
-
break;
-
}
-
}
-
for (x = 0; x <navigator.plugins.length; x++) {
-
if (navigator.plugins[x].name.indexOf('Java(TM)') != -1) {
-
java_installed = 1;
-
break;
-
}
-
}
-
}
-
-
// The other way to check if Java is enabled
-
if (navigator.javaEnabled()) {
-
java_installed = 1;
-
}
-
-
// ActiveX style plugin detection
-
else if (window.ActiveXObject) {
-
for (x = 2; x <= flash_versions; x++) {
-
try {
-
oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
-
if (oFlash) {
-
flash_installed = 1;
-
flash_version = x + '.0';
-
}
-
}
-
catch(e) { }
-
}
-
}
Here are today's counts from W3Counter.com itself:
I have a hard time believing only 50% of the site's visitors have Flash installed. Is it a logic error in my JavaScript (not one of the languages I'm more experienced with), or is attempting to detect Flash with only JavaScript futile?
I'd appreciate if anyone that's tackled this problem before could share their experience, as I'd rather not drop those reports from W3Counter.





ernie
January 26th, 2007
Looks like the activeX check only gets done if there is no Java. I think you stuck:
// The other way to check if Java is enabled
if (navigator.javaEnabled()) {
java_installed = 1;
}
in the middle of an if-the-else instead of the end.
Also you can harness the power of content addressable arrays by just using:
var x = navigator.plugins["Shockwave Flash"];
if (x && x.description) {….}
Ernie
Stuart Langridge
March 20th, 2007
Surely, though, you’re not catering there for the “navigator.javaEnabled() fails in IE6 sometimes” problem? I’m also looking for a way to reliably detect whether there’s Java installed, and I can’t work it out either
You’re checking the Netscape .plugins array, cool, but there’s no IE check other than navigator.javaEnabled which we know is buggy…
Detecting JS, Flash, and Java in your browser | CloudSync Developer’s Blog
November 10th, 2008
[...] Detecting Flash and Java with JavaScript [...]