How can I detect if Flash is installed and if not,

2019-01-02 19:50发布

How can I use javascript/jQuery/etc to detect if Flash is installed and if it isn't, display a div that contains information informing the user that they need to install flash?

8条回答
明月照影归
2楼-- · 2019-01-02 20:00

jqplugin: http://code.google.com/p/jqplugin/

$.browser.flash == true
查看更多
十年一品温如言
3楼-- · 2019-01-02 20:02

Use swfobject. it replaces a div with the flash if it is installed. see: http://code.google.com/p/swfobject/

查看更多
有味是清欢
4楼-- · 2019-01-02 20:13

You should also be able to use..

swfobject.getFlashPlayerVersion().major === 0

with the swfobject-Plugin.

查看更多
荒废的爱情
5楼-- · 2019-01-02 20:16

If swfobject won't suffice, or you need to create something a little more bespoke, try this:

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

It works with 7 and 8.

查看更多
妖精总统
6楼-- · 2019-01-02 20:19

@Drewid's answer didn't work in my Firefox 25 if the flash plugin is just disabled but installed.

@invertedSpear's comment in that answer worked in firefox but not in any IE version.

So combined both their code and got this. Tested in Google Chrome 31, Firefox 25, IE 8-10. Thanks Drewid and 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;
  }
}
查看更多
刘海飞了
7楼-- · 2019-01-02 20:19

You can use navigator.mimeTypes.

if (navigator.mimeTypes ["application/x-shockwave-flash"] == undefined)
    $("#someDiv").show ();
查看更多
登录 后发表回答