检测flash 版本

旧街凉风 提交于 2020-01-19 21:47:59
var nav = navigator;

var module =  {
    Plugins: {
            list: function() {
                var list = [];
                if (nav.plugins) {
                    for (var i = 0, l = nav.plugins.length; i < l; i++)
                    {
                        var plugin = {};

                        if (nav.plugins[i].name) {
                            plugin.name = nav.plugins[i].name;
                        }

                        if (nav.plugins[i].description) {
                            plugin.description = nav.plugins[i].description;
                        }

                        list[list.length] = plugin;
                    }                    
                }

                return list;
            },
            get: function (name) {
                for (var i = 0, l = nav.plugins.length; i < l; i++)
                {
                    if (nav.plugins[i].name === name) {
                        return nav.plugins[i];
                    }
                }
                return undefined;
            },
            
            Flash: {
                version: function () {
                    var vers   = 0;
                    var plugin = module.Plugins.get("Shockwave Flash");
                    
                    if (plugin !== undefined) {                        
                        vers = parseFloat(plugin.description.match(/\d{1,2}/));
                    } else {
                        // Test IE
                        var minVersion = 9;
                        var maxVersion = 12;                        
                        for (var i = maxVersion; i >= minVersion; i--)
                        {
                            try
                            {
                                var test = new win.ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
                                return i;
                            }
                            catch (e) { /* nothing to see here*/ }
                        }                        
                    }

                    return vers;
                }
            },
            
            Silverlight: {           
                version: function () {
                    var vers   = 0;
                    var plugin = module.Plugins.get("Silverlight Plug-In");
                    
                    if (plugin !== undefined) {
                        vers = parseFloat(plugin.description.match(/\d{1,2}/));
                    } else {
                        // Test IE
                        try {
                            var control = new win.ActiveXObject('AgControl.AgControl');
                            if (control) {
                                var minVersion = 3;
                                var maxVersion = 6;
                                for (var i = minVersion; i <= maxVersion; i++)
                                {
                                    if (control.isVersionSupported(i + ".0")) {
                                        vers = i;
                                    }
                                }
                            }
                        } catch (e) { /* nothing to see here*/ }
                    }

                    return vers;
                }
            }
        }
    };

console.log(module.Plugins.Flash.version());
alert(module.Plugins.Flash.version());

 http://www.pinlady.net/PluginDetect/guide/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!