我正在尝试检测Flash支持,我正在尝试按照这个答案进行操作:Cross Browser Flash Detection in Javascript
我的代码如下,但我总是得到同样的错误:未定义swfobject。我不应该这样做因为我在支持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");
}
这是最新浏览器的问题吗?有没有其他方法可以检测到它?
答案 0 :(得分:2)
如果未定义CURLOPT_URL
,则表示您缺少必需的JavaScript文件。您可以通过CDN加载https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js
答案 1 :(得分:1)
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");
}
答案 2 :(得分:0)
尝试检查typeof
object
,如下所示:
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");
}