Javascript method to get flash version number

  • 2020-03-30 04:21:00
  • OfStack

This article illustrates how javascript can get a flash version number. Share with you for your reference. Specific analysis is as follows:

Next, we will introduce two js functions to determine whether the user has installed flash, if the installation of flash to get flash version number and give a hint.

Case 1
Gets the version number of each browser, and gets the specific version number number if needed

function flashChecker() {
    var hasFlash = 0; //Is flash
installed     var flashVersion = 0; //Flash version
    var isIE =0; //Internet explorer
    if (isIE) {
        var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if (swf) {
            hasFlash = 1;
            flashVersion = swf.GetVariable("$version");
        }
    } else {
        if (navigator.plugins && navigator.plugins.length > 0) {
            var swf = navigator.plugins["Shockwave Flash"];
            if (swf) {
                hasFlash = 1;
                flashVersion = swf.description.split(" ");
            }
        }
    }
    return {
        f: hasFlash,
        v: flashVersion
    };
}
 
var fls = flashChecker();
if (fls.f) document.write(" You install the flash, The current flash Version for : " + fls.v + ".x");
else document.write(" You did not install flash");

Case 2
function getFlashVersion() {
     var flashVer = NaN;
     var ua = navigator.userAgent;
 
     if (window.ActiveXObject) {
         var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
 
         if (swf) {
             flashVer = Number(swf.GetVariable('$version').split(' ')[1].replace(/,/g, '.').replace(/^(d+.d+).*$/, "$1"));
         }
     } else {
         if (navigator.plugins && navigator.plugins.length > 0) {
             var swf = navigator.plugins['Shockwave Flash'];
 
             if (swf) {
                 var arr = swf.description.split(' ');
                 for (var i = 0, len = arr.length; i < len; i++) {
                     var ver = Number(arr[i]);
 
                     if (!isNaN(ver)) {
                         flashVer = ver;
                         break;
                     }
                 }
             }
         }
     }
     return flashVer;
 }
 var flashVer = getFlashVersion();
 if (!isNaN(flashVer)) {
     document.write(' The current flash player Version: ' + flashVer);  
 } else {
     document.write(' You have not installed flash player ');
}


Related articles: