If flash is installed

1.1k views Asked by At

I'm trying to make simple check if flash is installed like it was suggested here

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">
$( document ).ready(function() {
    console.log( "ready!" );
    if (!$.flash.hasVersion('9')) { //error
        //has Flash
        console.log( "flash installed!" );
        ...

But I get error, what is wrong here?

TypeError: $.flash is undefined

2

There are 2 answers

0
Z-Bone On

This should work...

function flashExists() {
    for (var i in navigator.plugins) {
        if (navigator.plugins[i].name && navigator.plugins[i].name.toString().indexOf('Flash') > -1) {
            return true;
        }
    }
    return false;
}
0
pipwerks On

Your code is returning an error because SWFObject and jQuery are two completely unrelated libraries. SWFObject has no $.flash object.

To check if Flash is available using SWFObject, do the following:

var meetsMinimumFlashRequirement = swfobject.hasFlashPlayerVersion("9");

if(meetsMinimumFlashRequirement){
   //Use Flash
} else {
   //Flash not available, use a fallback
}

See LearnSWFObject.com for more details and examples. http://learnswfobject.com/advanced-topics/detecting-flash-player-version-using-swfobject/index.html

I suspect the code you're using is based on a jQuery wrapper for SWFObject. If this is the case, you didn't include the source for the wrapper in your page, therefore the wrapper fails. Personally, I'd just use SWFObject directly.

(Actually, I wouldn't use Flash at all, but if I had to use Flash, I'd use SWFObject directly.)