0

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?

Community
  • 1
  • 1
Vandervals
  • 5,774
  • 6
  • 48
  • 94

3 Answers3

2

If swfobject is not defined, you are missing the required JavaScript file. You can load via CDN here https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js

pipwerks
  • 4,440
  • 1
  • 20
  • 24
1

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");
}
Vandervals
  • 5,774
  • 6
  • 48
  • 94
0

Try checking for the typeof the object like this:

if(typeof swfobject != "undefined"){ //Check if type of the object is undefined

    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");
}
Zee
  • 8,420
  • 5
  • 36
  • 58