How can I detect if Flash is installed and if not, display a hidden div that informs the user?
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
Comments
-
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 over 13 yearsthis works nice if you just want to detect if it is installed and not necessarily display a swf either way.
-
invertedSpear about 13 yearsHad to modify this to: var hasFlash = false; try { 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; }"
-
Kevin about 13 yearsthat won't work on IE7, as you're not testing the activexobject part
-
Alex W about 10 yearsupvote for using 5 lines of JavaScript instead of using an entire library
-
Gogol almost 10 yearssolid answer. Thnx for the life saver :)
-
Maniprakash Chinnasamy over 9 yearsThis will work for android mobile browser like firefox and chrome ?
-
mikemaccana over 9 years
swfobject
is undefined. -
Vladimir Vukanac almost 9 yearsWorks in Firefox 39 (2015-08-03).
-
zooblin over 8 yearsnice solution, but in the catch case I prefer to check :
(typeof navigator.mimeTypes['application/x-shockwave-flash'] !== 'undefined')
-
Aameer over 8 yearssolution was not working for ubuntu14.04 firefox(44.0) but @inverrtedSpear with your changes solution worked fine.
-
Jose Ignacio Hita almost 8 yearsThis is only working if the user hasn't installed Flash Player, but it's not working if it's installed but deactivated.
-
trainoasis almost 8 yearsWhat 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 almost 8 yearsIt 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 over 7 yearsVery nice. Thanks !
-
tmarois over 7 yearsNo longer works in Firefox 50+ tested 2017, still says "true" when I "block" flash from running on website.
-
1Mayur about 5 yearshow do we dispose fo object afterwards?
-
1Mayur about 5 yearsseems like it is taking up memory and not release everytime this code runs. IE11 on win 7 specifically
-
Sohail Faruqui about 4 yearsshort and sweet