例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"); |
例2
代码如下 | 复制代码 |
function getFlashVersion() { 2: var flashVer = NaN; 3: var ua = navigator.userAgent; 4: 5: if (window.ActiveXObject) { 6: var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); 7: 8: if (swf) { 9: flashVer = Number(swf.GetVariable('$version').split(' ')[1].replace(/,/g, '.').replace(/^(d+.d+).*$/, "$1")); 10: } 11: } else { 12: if (navigator.plugins && navigator.plugins.length > 0) { 13: var swf = navigator.plugins['Shockwave Flash']; 14: 15: if (swf) { 16: var arr = swf.description.split(' '); 17: for (var i = 0, len = arr.length; i < len; i++) { 18: var ver = Number(arr[i]); 19: 20: if (!isNaN(ver)) { 21: flashVer = ver; 22: break; 23: } 24: } 25: } 26: } 27: } 28: 29: return flashVer; 30: } 31: 32: 33: var flashVer = getFlashVersion(); 34: 35: if (!isNaN(flashVer)) { 36: 37: document.write('当前flash player 的版本:' + flashVer); 38: 39: } else { 40: document.write('您尚未安装flash播放器'); 41: } |