Skip to content

Instantly share code, notes, and snippets.

@getify
Created November 13, 2010 17:18
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save getify/675496 to your computer and use it in GitHub Desktop.
Save getify/675496 to your computer and use it in GitHub Desktop.
detecting if flash plugin is installed
var _flash_installed = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));
@mathiasbynens
Copy link

If you’re using Flash to progressively enhance a document, please use this script to feature detect it first. If Flash is not supported, there’s no point in embedding it — it will only cause useless, annoying “missing plugin” signs.

@jdalton
Copy link

jdalton commented Apr 12, 2011

If you have access to the flash element you want to use then "Pan" in element should do as an easy inference. More info here.

@the0ther
Copy link

i get a JS error in IE 8 when I try to run the (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false) portion from the Developer Tools. is anybody else getting this error? it goes away when I change the != to a !==.

@getify
Copy link
Author

getify commented Jun 17, 2011

do u get the error in IE on a normal page or just inside devtools?

@the0ther
Copy link

I get it on the page. I just tested this in IE6 and IE8. I get the generic "Object doesn't support this property or method" error message.

@chustedde
Copy link

In more recent versions of IE, you will get an error from new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), so instead you can use a try/catch:
var ie_flash; try { ie_flash = (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false) } catch(err) { ie_flash = false; } var _flash_installed = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || ie_flash);

@petercarter
Copy link

The test in SWFObject is not
if (window.ActiveXObject....)
but
if (typeof window.ActiveXObject !='undefined' .....)

@JamesMGreene
Copy link

@JamesMGreene
Copy link

Also, this appears to be the most stable version I've encountered: https://code.google.com/p/doctype-mirror/wiki/ArticleDetectFlash#The_code

@jdunne-kaplan
Copy link

Don't use this code; it fails in IE8. If flash is uninstalled, IE8 fails with "Automation server can't create object" error thrown. If flash is installed, IE8 fails anyway with "Object doesn't support this property or method" which I've isolated to the usage of the != operator instead of !== which does work. Either way, this cannot be reduced to a simple expression because the error is being thrown. It must be rewritten with some try/catch logic.

@jdunne-kaplan
Copy link

Best version so far is a slightly modified version of chustedde's code but with an !== false check instead of != false:

var ie_flash; try { ie_flash = (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) !== false) } catch(err) { ie_flash = false; } var _flash_installed = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || ie_flash); _flash_installed;

The last _flash_installed; statement is to have the JS console report the final result. Without it, Chrome, for example, would report "undefined".

@jdunne-kaplan
Copy link

@snshastry
Copy link

Am facing an issue with latest Firefox 55 (win64). navigator.plugins is not returning "Shockwave Flash" even though flash is installed.
Could anyone suggest how to resolved this.
Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment