6

First of all, sorry for ressurrecting this question here. I've been trying for two days how to reach this job using javascript/jquery and i think i've read all stack overflow and other blogs posts about that, so please, don't mark it as duplicated because I can't use out-dated scripts from 2012 now in 2017.

I've a single page that redirects to a third party e-learning platform where some content needs flash to work. Many users don't care about which software is installed on their machines (what a new, huh) so i need to detect it and show the tipical message "please install/update flash player clicking here", but i cannot find a "modern" script/way to do this, in any place, simplified, if possible.

All scripts i've tried are deprecated or returns false in all browsers, even i've newest version of flash installed and active.

Anny help will be appreciated (except links to older posts or scripts that don't work nowadays, obviously).

Thanks a lot!

2

2 Answers 2

5

There is a simple way to check for Flash since all the installed and enabled plugins will be listed in navigator.plugins;

Note that if a plugin is installed, but not enabled, it will not be detected in the navigator.plugins array. There is NO way to detect this using Javascript (this Question which confirms the same).

Having said that, use the following function isFlashEnabled(); to detect Flash :

<html>

<script>

if(isFlashEnabled()) 
{ document.write('Flash is installed (but may need to be enabled)'); } 
else { document.write('Flash is either not installed or disabled'); }

function isFlashEnabled() 
{
    var flash = navigator.plugins.namedItem('Shockwave Flash');
    if (!flash) { return 0; } 
    else { return 1; }
}

</script>

<body> <embed src="https://www.w3schools.com/tags/helloworld.swf"> </body>

</html>
7
  • @JoëlBonetRodríguez yes, being vanilla JS/native JS, this is cross-browser compatible. Tested on Chrome, Firefox, Opera and Safari (on MacOS, ubuntu) Not tested on IE but I am certain that it should work for IE9+ Commented Mar 16, 2017 at 19:12
  • Besides, that this is almost the exact same answer I posted some days ago, how did u manage to get it work on firefox? At least for me it doesn't work with the latest version.
    – opp
    Commented Mar 17, 2017 at 9:15
  • @opp because my answer and your answer are almost the same, but aren't exactly the same. In my answer, I am checking for installed plugins in the global plugins array alone, and that's why my solution works for all the browsers, including Firefox (you can try running the snippet on FF to verify) Commented Mar 17, 2017 at 9:56
  • In the second code block (from mozilla) I'm checking also only for the named plugin. But never mind! The snippet is not working on my latest FF (v 52.0)
    – opp
    Commented Mar 17, 2017 at 10:01
  • 1
    This check even works for modern tools that emulate flash (like ruffle.rs). Fantastic!
    – bryanbraun
    Commented Feb 3 at 11:57
0

You can get an array which contains all installed plugins of a browser like this:

var plugins = navigator.plugins;

Then you can then check if the array contains the flash plugin.

From https://developer.mozilla.org/de/docs/Web/API/NavigatorPlugins/plugins:

function getFlashVersion() {
   var flash = navigator.plugins.namedItem('Shockwave Flash');
   if (typeof flash != 'object') {
      // flash is not present
      return undefined;
   }
   if(flash.version){ 
     return flash.version;
   } else {
     //No version property (e.g. in Chrome)
     return flash.description.replace(/Shockwave Flash /,"");
  }
}
4
  • Thanks a lot! I'll try it as soon as possible (when time assigned to this job) and i'll give feedback.
    – JoelBonetR
    Commented Mar 13, 2017 at 22:17
  • On firefox i'm getting an error (flash is not defined) on a PC where flash is installed... Do you know why?
    – JoelBonetR
    Commented Mar 15, 2017 at 8:20
  • I guess due to security reasons its no longer possible to detect if flash is installed or not on firefox.
    – opp
    Commented Mar 17, 2017 at 9:13
  • @JoëlBonetRodríguez how did you get the error? I'm not getting any response from Firefox. Just blank page (even after trying document.write for feedback text).
    – VC.One
    Commented Mar 19, 2017 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.