Check for Flash-enabled browsers (using JavaScript)

Something most web developers take for granted is the ability of our user’s browser to render Flash. When working with BCD’s product suite, this is particularly true whenever we do any development with SmartCharts. But as you may be aware, there are some browsers which can not actually render Flash objects – namely the iPhone and iPad versions of Safari. These users not only fail to see any of your Flash content, but they also tend to receive a popup error message for every flash object you put on a page. So, in addition to missing out on some key functionality of your page, they also get an annoying alert (or three, or five, or ten…).

Putting aside lessons learned about gracefully handling errors, there is something that can be done about browsers without Flash enabled. Simple JavaScript can check a browser for its current Flash capability (that means browsers which can use Flash, but don’t happen to have it enabled/installed), which can then be handled any way you want.

Consider this code:

function getFlashVersion() {
    // ie
    try {
        try {
            // avoid fp6 minor version lookup issues
            // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
            var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
            try {
                axo.AllowScriptAccess = 'always';
            }
            catch(e) {
                return '6,0,0';
            }
        }
        catch(e) {}
        return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
    }
    // other browsers
    catch(e) {
        try {
            if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
                return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
            }
        }
        catch(e) {}
    }
    return '0,0,0';

}

var FlashVersion = getFlashVersion();

The Variable FlashVersion is global in this case, and will contain a string representing the current version of Flash installed (ex: 10,1,53). From here cases where Flash is not enabled can be handled using any method you would like. This usually involves providing alternate text stating what the user is missing out on, showing a text-based navigation menu, or linking to audio and visual media.

Eventually HTML5 hopes to address some of these problems, but until then you can at least handle non-Flash cases gracefully.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>