swfobject 未定义错误

swfobject not defined error

我正在尝试检测 Flash 支持,并且我正在尝试按照以下答案进行操作:Cross Browser Flash Detection in Javascript

我的代码如下,但我总是得到同样的错误:swfobject is not defined。我不应该得到它,因为我在支持 flash 的浏览器中尝试它(chrome 和 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");
}

这是最新浏览器的问题吗?有没有其他检测方法?

尝试像这样检查 typeofobject

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");
}

MDN page on flash 带领我走上了一条完全不同的道路:

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");
}

如果未定义 swfobject,则您缺少所需的 JavaScript 文件。您可以在此处通过 CDN 加载 https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js