借助JavaScript脚本判断浏览器Flash Player信息的方法

作者:窗边听雨

时间:2026-10-28

浏览:524

本文介绍如何利用JavaScript脚本检测浏览器中Flash Player的安装状态及具体版本号。通过区分IE与非IE浏览器,分别采用ActiveXObject与插件对象获取信息,并支持版本低于10时自动跳转至Adobe官方下载页面,适用于需要Flash支持的Flex应用测试与兼容性处理。

文章目录

Flash Player检测背景与需求

在研究Flex技术并制作小型Demo的过程中,测试时频繁出现报错。经排查发现,问题根源在于浏览器中安装的Flash Player版本过低,系统要求版本需为10及以上。针对这一情况,本文总结了通过JavaScript脚本获取浏览器Flash Player相关信息的检测方法。

JavaScript检测实现代码


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>JavaScript判断浏览器Flash Player信息</title> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
<script type="text/javascript"> 
function checkFlashPlayer(){ 
var hasFlashPlayer=0; //判断是否安装了Flash Player 
var flashPlayerVersion=0; //Flash Player版本 
if(document.all){ 
var shockWaveFlash = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); 
if(shockWaveFlash) { 
hasFlashPlayer=1; 
flashPlayerVersion=parseInt(shockWaveFlash.GetVariable("$version").split(" ")[1].split(",")[0]); 
} 
}else if (navigator.plugins && navigator.plugins.length > 0){ 
var shockWaveFlash=navigator.plugins["Shockwave Flash"]; 
if (shockWaveFlash){ 
hasFlashPlayer=1; 
var descriptionInfo = shockWaveFlash.description.split(" "); 
for (var i = 0; i < descriptionInfo.length; ++i){ 
if (isNaN(parseInt(descriptionInfo[i]))){ 
continue; 
} 
flashPlayerVersion = parseInt(descriptionInfo[i]); 
} 
} 
} 
return {hasFlashPlayer:hasFlashPlayer, flashPlayerVersion:flashPlayerVersion}; 
} 

if(checkFlashPlayer().hasFlashPlayer){ 
if(checkFlashPlayer().flashPlayerVersion <= 10){ 
if(confirm("您的Flash Player版本过低,立即升级Flash Player版本?")){ 
window.location.href="http://get.adobe.com/cn/flashplayer/" rel="external nofollow" rel="external nofollow" ; 
} 
}else{ 
alert("您安装了Flash Player,当前Flash Player版本号为:"+checkFlashPlayer().flashPlayerVersion+"。"); 
} 
}else{ 
if(confirm("您没有安装Flash Player,立即安装?")){ 
window.location.href="http://get.adobe.com/cn/flashplayer/" rel="external nofollow" rel="external nofollow" ; 
} 
} 
</script> 
</head> 

<body> 
</body> 
</html>

实用工具推荐

电子包浆

绿化、压缩、噪点和虚拟水印,自由调节做旧程度。

使用 ›
图片压缩

选择画质和输出格式,预览压缩前后的大小。

使用 ›
相关文章