How can I detect if Flash Player is disabled in a browser using JavaScript?

后端 未结 4 1729
我寻月下人不归
我寻月下人不归 2021-01-06 14:53

I know how to detect if Flash player is installed in a browser. I\'m using the hasFlashPlayerVersion() function of swfobject for that. However, I can\'t seem to fin

相关标签:
4条回答
  • 2021-01-06 15:38

    You could make a javascript call in an invisible swf that communicates with the browser's javascript. If a timeout occurs, then it is because the browser does not have flash player installed, or the flash player has been disabled.

    getURL("javascript:jsfunction();");
    
    0 讨论(0)
  • 2021-01-06 15:43

    Here is a nice library I'm using: http://www.featureblend.com/javascript-flash-detection-library.html

    0 讨论(0)
  • 2021-01-06 15:49

    I don't think it is possible to detect if flash is installed but disabled.

    If someone disables Flash, they might not want to tell if it's just disabled or not installed at all. Therefore a browser just tells you it is 'not available'.

    0 讨论(0)
  • 2021-01-06 15:59

    I agree with Ape and have done something similar a LONG time ago with a page that said something like "detecting flash player..." and waited 20 seconds while a swf file would load and immediately redirect the browser off the page.

    If the timer expired (the swf never loaded), it would prompt the user to install Flash.

    It would be possible to combine that approach with the swfobject hasFlashPlayerVersion() function you mentioned. If they have flash but the swf never loads, then it's fairly safe to assume that flash is disabled.

    So, there's really only 3 options:

    • No Flash
    • Flash: Enabled
    • Flash: Disabled

    In pseudo code, that could look like the following:

    var hasFlash = detectFlashPlayerInstalled();
    var flashEnabled = false;
    
    /* attempt to load the swf file then wait for some time, then... */
    
    var isDisabled = hasFlash && !flashEnabled;
    

    That works along with javascript functions like:

    function flashAlive() {
        flashEnabled = true;
    }
    function detectFlashPlayerInstalled() { 
        //TODO: detect flash in a better way, this will do for now
        return swfobject.hasFlashPlayerVersion(VERSION);
    }
    

    called from a tiny swf file containing:

    getURL("javascript:flashAlive();");
    

    I hope that helps in some way.

    0 讨论(0)
提交回复
热议问题