如何检测Flash是否已安装,如果没有,则显示隐藏的div以通知用户?

Kin*_*tor 88 javascript flash asp.net-mvc jquery detection

如何使用javascript/jQuery/etc来检测Flash是否已安装,如果不是,则显示包含告知用户需要安装Flash的信息的div?

Dre*_*wid 160

如果swfobject不够,或者您需要创建一些更定制的东西,请尝试以下方法:

var hasFlash = false;
try {
    hasFlash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
} catch(exception) {
    hasFlash = ('undefined' != typeof navigator.mimeTypes['application/x-shockwave-flash']);
}
Run Code Online (Sandbox Code Playgroud)

它适用于7和8.

  • 不得不将其修改为:var hasFlash = false; 试试{var fo =(navigator.mimeTypes && navigator.mimeTypes ['application/x-shockwave-flash'])?navigator.mimeTypes ['application/x-shockwave-flash'].enabledPlugin:0; if(fo)hasFlash = true; } catch(e){if(navigator.mimeTypes ['application/x-shockwave-flash']!= undefined)hasFlash = true; }" (10认同)
  • 如果您只想检测它是否已安装并且不一定以任何方式显示swf,这都很好用. (2认同)

Vig*_*ran 104

如果Flash插件刚刚被禁用但已安装,@ Drewid的答案在我的Firefox 25中无效.

@vertedSpear在该答案中的评论在firefox中有效但在任何IE版本中都没有.

所以结合他们的代码并得到了这个.在Google Chrome 31,Firefox 25,IE 8-10中测试过.谢谢Drewid和invertedSpear :)

var hasFlash = false;
try {
  var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  if (fo) {
    hasFlash = true;
  }
} catch (e) {
  if (navigator.mimeTypes
        && navigator.mimeTypes['application/x-shockwave-flash'] != undefined
        && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
    hasFlash = true;
  }
}
Run Code Online (Sandbox Code Playgroud)


Jos*_*osh 26

使用swfobject.如果安装了flash,它会用flash替换div.请参阅:http://code.google.com/p/swfobject/


alb*_*ein 18

您可以使用navigator.mimeTypes.

if (navigator.mimeTypes ["application/x-shockwave-flash"] == undefined)
    $("#someDiv").show ();
Run Code Online (Sandbox Code Playgroud)