FlashMode = 0;
if (navigator.plugins && navigator.plugins.length > 0)
{
if (navigator.plugins["Shockwave Flash"])
{
var plugin_version = 0;
var words = navigator.plugins["Shockwave Flash"].description.split(" ");
for (var i = 0; i < words.length; ++i)
{
if (isNaN(parseInt(words[i])))
continue;
plugin_version = words[i];
}
if (plugin_version >= 5)
{
var plugin = navigator.plugins["Shockwave Flash"];
var numTypes = plugin.length;
for (j = 0; j < numTypes; j++)
{
mimetype = plugin[j];
if (mimetype)
{
if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("swf") != -1))
FlashMode = 1;
// Mac wierdness
if (navigator.mimeTypes["application/x-shockwave-flash"] == null)
FlashMode = 0;
}
}
}
}
}
if (FlashMode == 1)
{
document.write('有FLASH的HTML');}
else {
document.write('无FLASH的HTML'); }
// end JS detection -->
通过以下的Javascript脚本,可以检测当前浏览器是否安装Flash插件以及插件的版本是否满足要求。
代码如下:
// U can change this number to check specific version of flash
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ?
navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
var words = navigator.plugins["Shockwave Flash"].description.split(" ");
for (var i = 0; i < words.length; ++i){
if (isNaN(parseInt(words[i])))
continue;
var MM_PluginVersion = words[i];
}
var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if( navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 &&
(navigator.appVersion.indexOf("Win") != -1) ) {
//FS hide this from IE4.5 Mac by splitting the tag
document.write('
document.write('on error resume next \n');
document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
document.write('
}
if ( MM_FlashCanPlay ) {
alert("Flash Detection OK. U can play.");
}
else{
alert("Flash Detection Failed. Need Download specific version.");
}
//-->
//自己总结的
//IE中判断是否安装插件
var swf;
function IE_Flash()
{
try
{
var swf=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
alert("已安装插件");
}
catch(e)
{
alert("没有安装插件");
}
}
//FireFox,Chrome中判断是否安装插件
function FF_or_Chrome_Flash()
{
var swf=navigator.plugins["Shockwave Flash"];
(swf)?alert("已安装插件"):alert("没有安装插件");
}
script>