Article
Flash Player Detection Techniques Unearthed
Client Side Scripting using Javascript and VBScript
This method is the most widely used among the development community. It involves employing client side scripts to check for Flash Player version information, then uses conditionals (if...else) to determine what to do based on the results that are returned.
To employ client side scripting, we have to know how the Player is installed and handled by different browsers and operating systems.
All browsers, apart from Internet Explorer 5, 5.5 and 6 for Windows, handle the Player using the Netscape Plugin API. This means that once the Player is installed, version information is available to scripts via the Javascript Navigator.plugins array.
As with most things on the Web, the Internet Explorer versions noted above handle things differently. These browsers support Flash using Microsoft's ActiveX technology and do not support the Navigator.plugins array. To detect version information in these situations, Microsoft's own scripting language VBScript needs to be employed.
Luckily for us, Netscape-compatible browsers such as Mozilla, Netscape 7, Internet Explorer 5 for the Mac, Safari, Opera and Netscape Navigator 4 ignore VBScript entirely, and we can use this to our advantage when developing client side detection techniques.
Code example
Below is script that checks for Flash Player 6 on the user's machine. If a version that's lower than this is detected, or no version is detected, alternate, descriptive content is displayed -- as per the W3C recommendation. Note that the script tags are XHTML compliant.
<script type="text/vbscript">
<!--
//check for Flash Player X
//script for IE on Win32 systems
on error resume next
//set a variable to hold the detection result
Dim checkForFlash6
//assign a boolean value
checkForFlash6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))
//note here that if the object is demoted to ShockwaveFlash.ShockwaveFlash.5 or less, checkForFlash6 will still return true
//this is ok as Flash Player 6 can run previous version content.
//change 6 to 7 and you will see the alternate content (if 7 is not installed).
//check that Shockwave Flash Plugin 6 is available
//if false display alternate content, if true show object tag
//quotes need to be doubled in vbscript in order for IE to render them in markup.
if checkForFlash6 = true then
document.write("<object data=""index.swf"" type=""application/x-shockwave-flash"" codebase=""http://www.example.com/"" width=""550"" height=""400""><param name=""movie"" value=""index.swf"" /><param name=""menu"" value=""false"" /><param name=""quality"" value=""high"" /><param name=""bgcolor"" value=""#ededed"" /></object>")
else
document.write("Alternate descriptive content can go here, plus a link to the Flash Player download page for the user to optionally activate.<br />This text will be rendered if the user-agent cannot render the file specified in the object tag.")
end If
-->
</script>
<script type="text/javascript">
<!--
//check for Flash Player X
//check the navigator.plugins array exists, IE for Windows will fail on this.
if(navigator.plugins.length)
{
//some variables
//a counter
var i;
var xhtmlContent = "<object data=\"index.swf\" type=\"application/x-shockwave-flash\" codebase=\"http://www.example.com/\" width=\"550\" height=\"400\"><param name=\"movie\" value=\"index.swf\" /><param name=\"menu\" value=\"false\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ededed\" /></object>";
var alternateContent = "Alternate descriptive content can go here, plus a link to the Flash Player download page for the user to optionally activate.<br />This text will be rendered if the user-agent cannot render the file specified in the object tag.";
//loop through all the plugins installed
for (i=0; i < navigator.plugins.length; i++)
{
//put the plugin string in a variable
var pluginIdent = navigator.plugins[i].description.split(" ");
//The Flash Player identification string is ([] = the array index) [0]Shockwave [1]Flash [2]6.0 [3]r21
//if less than Flash Player 6 is detected, run this code.
if(pluginIdent[0] == "Shockwave" && pluginIdent[1] == "Flash")
{
//set a toggle to show that some sort of Flash Player (of versions 1-5) was found
var isSwfEnabled = true;
//an array of the Flash version number (major.minor)
var versionArray = pluginIdent[2].split(".");
if(versionArray[0] < 6)
{
//show alternate content
document.write(alternateContent);
}
else
{
//Flash Player 6 or greater has been found, roll out the <object> tag.
document.write(xhtmlContent);
}
//need to break this loop as some browsers may have two versions installed
//eg my Firebird release has r65 and r79 installed!
break;
}//end if pluginIdent
}//end for
//check if no Shockwave Flash was detected in the array (no Flash Player installed)
if(!isSwfEnabled)
{
document.write(alternateContent);
}//end if
}
-->
</script>
The code used above shows how alternate content can be deployed to a browser depending on the script results. It doesn't utilise redirection, as I'm endeavouring to stick with the W3C recommendations in this article.