检测浏览器是否支持flash
1 var i_flash = false; 2 var v_flash = false; 3 // Netscape 4 if (navigator.plugins) { 5 for (var i = 0; i < navigator.plugins.length; i++) { 6 if (navigator.plugins[i].name.toLowerCase().indexOf("shockwave flash") >= 0) { 7 console.log(navigator.plugins[i].name.toLowerCase()); 8 i_flash = true; 9 v_flash = navigator.plugins[i].description.substring(navigator.plugins[i].description.toLowerCase().lastIndexOf("flash ") + 6, navigator.plugins[i].description.length); 10 } 11 } 12 } 13 if(!i_flash){ 14 if(confirm('是否下载控件')){ 15 window.open('https://get2.adobe.com/cn/flashplayer'); 16 } 17 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 if (document.all) { var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); if (swf) { hasFlash = 1; VSwf = swf.GetVariable("$version"); flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]); } } else { if (navigator.plugins && navigator.plugins.length > 0) { var swf = navigator.plugins["Shockwave Flash"]; if (swf) { hasFlash = 1; var words = swf.description.split(" "); for (var i = 0; i < words.length; ++i) { if (isNaN(parseInt(words[i]))) continue; flashVersion = parseInt(words[i]); } } } } return { f: hasFlash, v: flashVersion }; } var fls = flashChecker(); var s = ""; if (fls.f) alert("您安装了flash,当前flash版本为: " + fls.v + ".x"); else alert("您没有安装flash");