How can I detect if Flash is installed and if not, display a hidden div that informs the user?

119,242

Solution 1

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

Solution 2

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.

Solution 3

@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;
  }
}

Solution 4

You can use navigator.mimeTypes.

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

Solution 5

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

$.browser.flash == true
Share:
119,242
KingNestor
Author by

KingNestor

CS Student at the University of Central Missouri

Updated on February 05, 2020

Comments

  • KingNestor
    KingNestor over 4 years

    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?

  • MCF
    MCF over 13 years
    this works nice if you just want to detect if it is installed and not necessarily display a swf either way.
  • invertedSpear
    invertedSpear about 13 years
    Had to modify this to: var hasFlash = false; try { var fo = (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash']) ? navigator.mimeTypes['application/x-shockwave-flash'].enabled‌​Plugin : 0; if(fo) hasFlash = true; }catch(e){ if(navigator.mimeTypes ['application/x-shockwave-flash'] != undefined) hasFlash = true; }"
  • Kevin
    Kevin about 13 years
    that won't work on IE7, as you're not testing the activexobject part
  • Alex W
    Alex W about 10 years
    upvote for using 5 lines of JavaScript instead of using an entire library
  • Gogol
    Gogol almost 10 years
    solid answer. Thnx for the life saver :)
  • Maniprakash Chinnasamy
    Maniprakash Chinnasamy over 9 years
    This will work for android mobile browser like firefox and chrome ?
  • mikemaccana
    mikemaccana over 9 years
    swfobject is undefined.
  • Vladimir Vukanac
    Vladimir Vukanac almost 9 years
    Works in Firefox 39 (2015-08-03).
  • zooblin
    zooblin over 8 years
    nice solution, but in the catch case I prefer to check : (typeof navigator.mimeTypes['application/x-shockwave-flash'] !== 'undefined')
  • Aameer
    Aameer over 8 years
    solution was not working for ubuntu14.04 firefox(44.0) but @inverrtedSpear with your changes solution worked fine.
  • Jose Ignacio Hita
    Jose Ignacio Hita almost 8 years
    This is only working if the user hasn't installed Flash Player, but it's not working if it's installed but deactivated.
  • trainoasis
    trainoasis almost 8 years
    What if the flash is out of date ? Safari sometimes says it's out of date and it won't work until you update. How would I check for that?
  • Eugenio
    Eugenio almost 8 years
    It doesn't work if plugin are allowed but Flash is explicitely blocked for the website we are checking. Safari 8.0.8. In this case hasFlash is still true (should be false).
  • Koby Douek
    Koby Douek over 7 years
    Very nice. Thanks !
  • tmarois
    tmarois over 7 years
    No longer works in Firefox 50+ tested 2017, still says "true" when I "block" flash from running on website.
  • 1Mayur
    1Mayur about 5 years
    how do we dispose fo object afterwards?
  • 1Mayur
    1Mayur about 5 years
    seems like it is taking up memory and not release everytime this code runs. IE11 on win 7 specifically
  • Sohail Faruqui
    Sohail Faruqui about 4 years
    short and sweet