Search code examples
javascriptswfobject

swfobject not defined error


I'm trying to detect flash support, and I'm trying to proceed like in this answer: Cross Browser Flash Detection in Javascript

My code is the following, but I always get the same error: swfobject is not defined. I shouldn't get that because I'm trying it in browsers that do support flash (chrome and firefox).

if(swfobject){
    console.log("you have swfobject.");

    if(swfobject.hasFlashPlayerVersion("1")){
        console.log("You have flash!");
    }
    else{
        console.log("You do not flash :(");
    }
}else{
    console.log("you don't have swfobject");
}

Is this a problem with newest browsers? Is there any other way to detect it?


Solution

  • MDN page on flash led me through a completly diferent path:

    if(navigator.mimeTypes["application/x-shockwave-flash"]){
        var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
        var description = plugin.description;
        var versionArray = description.match(/[\d.]+/g);
        var flashVersionOSXScriptable = 12;
        var flashVersion = parseInt(versionArray[0]);
    
        if(navigator.userAgent.indexOf("Mach-O")==-1){
            if(flashVersion >= flashVersionOSXScriptable){
                console.log("you have flash");
            }else{
                console.log("you don't have flash");
            }
        }
    }else{
        console.log("you don't have flash");
    }