Cross Browser Flash Detection in Javascript

2019-01-01 14:33发布

Does anyone have an example of script that can work reliably well across IE/Firefox to detect if the browser is capable of displaying embedded flash content. I say reliably because I know its not possible 100% of the time.

15条回答
不再属于我。
2楼-- · 2019-01-01 15:27

Carl Yestrau's JavaScript Flash Detection Library, here:

http://www.featureblend.com/javascript-flash-detection-library.html

... may be what you're looking for.

查看更多
十年一品温如言
3楼-- · 2019-01-01 15:29

SWFObject is very reliable. I have used it without trouble for quite a while.

查看更多
何处买醉
4楼-- · 2019-01-01 15:30

I know this is an old post, but I've been looking for a while and didn't find anything.
I've implemented the JavaScript Flash Detection Library. It works very well and it is documented for quick use. It literally took me 2 minutes. Here is the code I wrote in the header:

<script src="Scripts/flash_detect.js"></script>
<script type="text/javascript"> 
 if (!FlashDetect.installed) {
    alert("Flash is required to enjoy this site.");         
 } else {
    alert("Flash is installed on your Web browser.");
 }
</script>        
查看更多
琉璃瓶的回忆
5楼-- · 2019-01-01 15:30

You could use closure compiler to generate a small, cross-browser flash detection:

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @formatting pretty_print
// @use_closure_library true
// ==/ClosureCompiler==

// ADD YOUR CODE HERE
goog.require('goog.userAgent.flash');
if (goog.userAgent.flash.HAS_FLASH) {
    alert('flash version: '+goog.userAgent.flash.VERSION);
}else{
    alert('no flash found');
}

which results in the following "compiled" code:

var a = !1,
    b = "";

function c(d) {
    d = d.match(/[\d]+/g);
    d.length = 3;
    return d.join(".")
}
if (navigator.plugins && navigator.plugins.length) {
    var e = navigator.plugins["Shockwave Flash"];
    e && (a = !0, e.description && (b = c(e.description)));
    navigator.plugins["Shockwave Flash 2.0"] && (a = !0, b = "2.0.0.11")
} else {
    if (navigator.mimeTypes && navigator.mimeTypes.length) {
        var f = navigator.mimeTypes["application/x-shockwave-flash"];
        (a = f && f.enabledPlugin) && (b = c(f.enabledPlugin.description))
    } else {
        try {
            var g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"),
                a = !0,
                b = c(g.GetVariable("$version"))
        } catch (h) {
            try {
                g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"), a = !0, b = "6.0.21"
            } catch (i) {
                try {
                    g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), a = !0, b = c(g.GetVariable("$version"))
                } catch (j) {}
            }
        }
    }
}
var k = b;
a ? alert("flash version: " + k) : alert("no flash found");
查看更多
柔情千种
6楼-- · 2019-01-01 15:30

Perhaps adobe's flash player detection kit could be helpful here?

http://www.adobe.com/products/flashplayer/download/detection_kit/

查看更多
若你有天会懂
7楼-- · 2019-01-01 15:31

Minimum version I've ever used (doesn't check version, just Flash Plugin):

var hasFlash = function() {
    return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0) ? !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) : navigator.plugins["Shockwave Flash"];
};
查看更多
登录 后发表回答