Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 249
KingNestor Avatar asked Jun 15 '09 20:06

KingNestor


2 Answers

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.

like image 78
Drewid Avatar answered Sep 28 '22 02:09

Drewid


@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;   } } 
like image 43
Vigneshwaran Avatar answered Sep 28 '22 01:09

Vigneshwaran