Home > Web Front-end > JS Tutorial > How to get flash version number using javascript

How to get flash version number using javascript

PHPz
Release: 2018-09-30 11:42:54
Original
2229 people have browsed it

这篇文章主要介绍了javascript获取flash版本号的方法,以实例形式分析了javascript判断用户是否安装了Flash及获取Flash版本号的方法,具有一定的实用价值,需要的朋友可以参考下,具体分析如下:

下面我们来介绍两个js函数判断用户是否安装了flash,如果安装了flash再来获取 flash版本号并且给出提示。

例1:获取各浏览器的版本号,如需获取具体版本号数字

function flashChecker() {
    var hasFlash = 0; //是否安装了flash
    var flashVersion = 0; //flash版本
    var isIE =/*@cc_on!@*/0; //是否IE浏览器
    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("您安装了flash,当前flash版本为: " + fls.v + ".x");
else document.write("您没有安装flash");
Copy after login

例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(&#39;当前flash player 的版本:&#39; + flashVer);   
 } else {
     document.write(&#39;您尚未安装flash播放器&#39;);
}
Copy after login

希望本章所述对大家的javascript程序设计有所帮助,更多相关教程请访问JavaScript视频教程

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template