Results 1 to 3 of 3

Thread: Detect Flash Player

  1. #1
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Detect Flash Player

    So,

    I got this flash detection kit form Adobe. It's almost perfect but what it currently does is display and alert every time showing your flash version. I only want it t display if they don't have the latest version. heres the code:

    Code:
    var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
    function ControlVersion()
    {
    var version;
    var axo;
    var e;
    try {
    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
    version = axo.GetVariable("$version");
    } catch (e) {
    }
    
    if (!version)
    {
    try {
    // version will be set for 6.X players only
    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
    
    // installed player is some revision of 6.0
    // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
    // so we have to be careful. 
    
    // default to the first public version
    version = "WIN 6,0,21,0";
    
    // throws if AllowScripAccess does not exist (introduced in 6.0r47)	
    axo.AllowScriptAccess = "always";
    
    // safe to call for 6.0r47 or greater
    version = axo.GetVariable("$version");
    
    } catch (e) {
    }
    }
    
    if (!version)
    {
    try {
    // version will be set for 4.X or 5.X player
    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
    version = axo.GetVariable("$version");
    } catch (e) {
    }
    }
    
    if (!version)
    {
    try {
    // version will be set for 3.X player
    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
    version = "WIN 3,0,18,0";
    } catch (e) {
    }
    }
    
    if (!version)
    {
    try {
    // version will be set for 2.X player
    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
    version = "WIN 2,0,0,11";
    } catch (e) {
    version = -1;
    }
    }
    
    return version;
    }
    
    // JavaScript helper required to detect Flash Player PlugIn version information
    function GetSwfVer(){
    // NS/Opera version >= 3 check for Flash plugin in plugin array
    var flashVer = -1;
    
    if (navigator.plugins != null && navigator.plugins.length > 0) {
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
    var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
    var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
    var descArray = flashDescription.split(" ");
    var tempArrayMajor = descArray[2].split(".");	
    var versionMajor = tempArrayMajor[0];
    var versionMinor = tempArrayMajor[1];
    var versionRevision = descArray[3];
    if (versionRevision == "") {
    versionRevision = descArray[4];
    }
    if (versionRevision[0] == "d") {
    versionRevision = versionRevision.substring(1);
    } else if (versionRevision[0] == "r") {
    versionRevision = versionRevision.substring(1);
    if (versionRevision.indexOf("d") > 0) {
    versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
    }
    }
    var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
    //alert("flashVer="+flashVer);
    }
    }
    // MSN/WebTV 2.6 supports Flash 4
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
    // WebTV 2.5 supports Flash 3
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
    // older WebTV supports Flash 2
    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
    else if ( isIE && isWin && !isOpera ) {
    flashVer = ControlVersion();//alert("control version="+flashVer);
    }	
    return flashVer;
    }

  2. #2
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    You should try swfobject instead. AFAIK, it is the industry standard for Flash detection and implementation. Check out this page:

    http://code.google.com/p/swfobject/w...ion(versionStr)
    My site: FreshCut :)

  3. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Code:
    SCRIPT FOR DETECTING FLASHPLAYER VERSION
    
    <script type="text/javascript">
    /*
    Original file: http://www.featureblend.com/javascript-flash-detection-library.html
    Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
    Code licensed under the BSD License: http://www.featureblend.com/license.txt
    Version: 1.0.4
    */
    var FlashDetect = new function(){
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
    {
    "name":"ShockwaveFlash.ShockwaveFlash.7",
    "version":function(obj){
    return getActiveXVersion(obj);
    }
    },
    {
    "name":"ShockwaveFlash.ShockwaveFlash.6",
    "version":function(obj){
    var version = "6,0,21";
    try{
    obj.AllowScriptAccess = "always";
    version = getActiveXVersion(obj);
    }catch(err){}
    return version;
    }
    },
    {
    "name":"ShockwaveFlash.ShockwaveFlash",
    "version":function(obj){
    return getActiveXVersion(obj);
    }
    }
    ];
    /
    * Extract the ActiveX version of the plugin.
    *
    * @param {Object} The flash ActiveX object.
    * @type String
    */
    var getActiveXVersion = function(activeXObj){
    var version = -1;
    try{
    version = activeXObj.GetVariable("$version");
    }catch(err){}
    return version;
    };
    /
    * Try and retrieve an ActiveX object having a specified name.
    *
    * @param {String} name The ActiveX object name lookup.
    * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
    * @type Object
    */
    var getActiveXObject = function(name){
    var obj = -1;
    try{
    obj = new ActiveXObject(name);
    }catch(err){
    obj = {activeXError:true};
    }
    return obj;
    };
    /
    * Parse an ActiveX $version string into an object.
    *
    * @param {String} str The ActiveX Object GetVariable($version) return value.
    * @return An object having raw, major, minor, revision and revisionStr attributes.
    * @type Object
    */
    var parseActiveXVersion = function(str){
    var versionArray = str.split(",");//replace with regex
    return {
    "raw":str,
    "major":parseInt(versionArray[0].split(" ")[1], 10),
    "minor":parseInt(versionArray[1], 10),
    "revision":parseInt(versionArray[2], 10),
    "revisionStr":versionArray[2]
    };
    };
    /
    * Parse a standard enabledPlugin.description into an object.
    *
    * @param {String} str The enabledPlugin.description value.
    * @return An object having raw, major, minor, revision and revisionStr attributes.
    * @type Object
    */
    var parseStandardVersion = function(str){
    var descParts = str.split(/ +/);
    var majorMinor = descParts[2].split(/\./);
    var revisionStr = descParts[3];
    return {
    "raw":str,
    "major":parseInt(majorMinor[0], 10),
    "minor":parseInt(majorMinor[1], 10),
    "revisionStr":revisionStr,
    "revision":parseRevisionStrToInt(revisionStr)
    };
    };
    /
    * Parse the plugin revision string into an integer.
    *
    * @param {String} The revision in string format.
    * @type Number
    */
    var parseRevisionStrToInt = function(str){
    return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /
    * Is the major version greater than or equal to a specified version.
    *
    * @param {Number} version The minimum required major version.
    * @type Boolean
    */
    self.majorAtLeast = function(version){
    return self.major >= version;
    };
    /
    * Is the minor version greater than or equal to a specified version.
    *
    * @param {Number} version The minimum required minor version.
    * @type Boolean
    */
    self.minorAtLeast = function(version){
    return self.minor >= version;
    };
    /
    * Is the revision version greater than or equal to a specified version.
    *
    * @param {Number} version The minimum required revision version.
    * @type Boolean
    */
    self.revisionAtLeast = function(version){
    return self.revision >= version;
    };
    /
    * Is the version greater than or equal to a specified major, minor and revision.
    *
    * @param {Number} major The minimum required major version.
    * @param {Number} (Optional) minor The minimum required minor version.
    * @param {Number} (Optional) revision The minimum required revision version.
    * @type Boolean
    */
    self.versionAtLeast = function(major){
    var properties = [self.major, self.minor, self.revision];
    var len = Math.min(properties.length, arguments.length);
    for(i=0; i<len; i++){
    if(properties[i]>=arguments[i]){
    if(i+1<len && properties[i]==arguments[i]){
    continue;
    }else{
    return true;
    }
    }else{
    return false;
    }
    }
    };
    /
    * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
    */
    self.FlashDetect = function(){
    if(navigator.plugins && navigator.plugins.length>0){
    var type = 'application/x-shockwave-flash';
    var mimeTypes = navigator.mimeTypes;
    if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
    var version = mimeTypes[type].enabledPlugin.description;
    var versionObj = parseStandardVersion(version);
    self.raw = versionObj.raw;
    self.major = versionObj.major;
    self.minor = versionObj.minor;
    self.revisionStr = versionObj.revisionStr;
    self.revision = versionObj.revision;
    self.installed = true;
    }
    }else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
    var version = -1;
    for(var i=0; i<activeXDetectRules.length && version==-1; i++){
    var obj = getActiveXObject(activeXDetectRules[i].name);
    if(!obj.activeXError){
    self.installed = true;
    version = activeXDetectRules[i].version(obj);
    if(version!=-1){
    var versionObj = parseActiveXVersion(version);
    self.raw = versionObj.raw;
    self.major = versionObj.major;
    self.minor = versionObj.minor;
    self.revision = versionObj.revision;
    self.revisionStr = versionObj.revisionStr;
    }
    }
    }
    }
    }();
    };
    FlashDetect.JS_RELEASE = "1.0.4";
    </script>
    
    POSSIBLE USE:
    if(FlashDetect.major<10)alert('You should upgrade your Flashplayer at http://get.adobe.com/flashplayer.');
    ===
    Arie Molendijk.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •