Skip to content

Instantly share code, notes, and snippets.

@dciccale
Forked from 140bytes/LICENSE.txt
Created July 31, 2011 09:30
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dciccale/1116643 to your computer and use it in GitHub Desktop.
Save dciccale/1116643 to your computer and use it in GitHub Desktop.
Detect if Flash Player is installed in your browser (120bytes)
function(
a, // 'Shockwave'
b, // 'Flash'
) {
// try creating an AxtiveXObject (internet explorer use this object)
try {
a = new ActiveXObject(a+b+'.'+a+b);
}
// if fails, is not ie, so check for the navigator.plugins object
catch ( e ) {
a = navigator.plugins[a+' '+b];
}
// return true/false
return!!a;
}('Shockwave','Flash') // auto-run passing the name of Flash Player plugin
function(a,b){try{a=new ActiveXObject(a+b+'.'+a+b)}catch(e){a=navigator.plugins[a+' '+b]}return!!a}('Shockwave','Flash')
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Denis Ciccale <http://webdecs.wordpress.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "hayFlash",
"description": "Detect if Flash Player is installed in your browser",
"keywords": [
"detect",
"flash",
"player",
"browser"
]
}
<!doctype html>
<head>
<title>Detect Flash Player</title>
<script>
var hayFlash = function(a,b){try{a=new ActiveXObject(a+b+'.'+a+b)}catch(e){a=navigator.plugins[a+' '+b]}return!!a}('Shockwave','Flash')
if(hayFlash) {
alert("Flash Player is installed");
}
else {
alert("Your browser doesn't have Flash Player installed");
}
</script>
</head>
<body>
</body>
</html>
@jed
Copy link

jed commented Aug 1, 2011

cool! your annotated version needs a bit of an update, though, since you're returning f currently.

@dciccale
Copy link
Author

dciccale commented Aug 1, 2011

done. thanks jed!

@jed
Copy link

jed commented Aug 1, 2011

@dciccale

also, you don't need a space between return and !!.

@dciccale
Copy link
Author

dciccale commented Aug 1, 2011

perfect, now is 123 bytes

@atk
Copy link

atk commented Aug 2, 2011

the replace statement is somewhat big. Without it, you have 3 bytes less:
function(a,b){try{a=new ActiveXObject(a+b+'.'+a+b)}catch(e){a=navigator.plugins[a+' '+b]}return!!a}('Shockwave','Flash')

@dciccale
Copy link
Author

dciccale commented Aug 2, 2011

perfect atk! thanks

@atk
Copy link

atk commented Aug 2, 2011

You're very welcome!

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