Accessibility

Flash Player Article

 

Future-Proofing Flash Player Detection Scripts


Table of Contents

Checking for More Than Just the Version You Need

This problematic situation, which shuts out visitors who have versions of Flash Player greater than the one for which you are checking, can be easily located in your detection script. Look for areas where version numbers are checked and parse the code in your head to make sure that, if version 8 is passed into the script, detection evaluates successfully. If not, you've identified areas that need to be modified.

For example, in most script- and SWF-based detection schemes, playerVersion represents the version of Flash Player on the visitor's computer and requiredVersion represents the version required to view the site content. Instead of permitting visitors only where playerVersion == requiredVersion to enter, detection should allow entry to visitors where playerVersion >= requiredVersion.

Here's an example of a JavaScript detection script with the problematic section highlighted:

function getFlashVersion() {
      var agent = navigator.userAgent.toLowerCase(); 
      
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
      // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
      if (navigator.plugins != null && navigator.plugins.length > 0) {
            var flashPlugin = navigator.plugins['Shockwave Flash'];
            if (typeof flashPlugin == 'object') { 
                  if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
                  else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
                  else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
                  else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
                  else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
            }
      }
}

The final statements which check for Flash don't take into account versions of Flash Player greater than 7. You could simply add another line for Flash Player 8, but that would only solve the problem until the next version arrives.

Here is an amended example of the same script that would run with any future versions (changes are highlighted):

function getFlashVersion() {

   var agent = navigator.userAgent.toLowerCase();
       flashVersion = 0; 
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
   if (navigator.plugins != null && navigator.plugins.length > 0) {
      var flashPlugin = navigator.plugins['Shockwave Flash']; 
      if (typeof flashPlugin == 'object') {
            for (i=25;i>0;i--) {
                  if (flashPlugin.description.indexOf(i+'.') != -1){ 
                           flashVersion = i;
              }
            }
      }
    }
}

This example solves the problem by checking for all possible versions of Flash Player, rather than just the ones you know about. However, this is just one of many workarounds that developers have implemented. The key thing to learn from this example is never to depend on a client's returning a specific version number. You can count on the version of Flash Player you know today to change within the next 18 months.

This example also illustrates the two most common problems found in player-detection scripts. First, it does not properly detect the type of browser and version of Flash Player that the client is running. Second, it does not account for versions of Flash Player the may exist in the future. Now that you have seen the most common mistakes, let's explore a complete solution.