如何判断客户端是否安装了某个插件?最常见的就是使用DHTML Behavior中的两个方法:
isComponentInstalled
但是msdn上有这么一句话:Only Microsoft Internet Explorer components are detected by this method. If a component identifier of a third-party component is specified, the method returns false。
为了解决问题,自己花了1个小时写了下面通用的方法,供大家参考:
但是msdn上有这么一句话:Only Microsoft Internet Explorer components are detected by this method. If a component identifier of a third-party component is specified, the method returns false。
为了解决问题,自己花了1个小时写了下面通用的方法,供大家参考:
<
HTML
>
< HEAD >
< script type ="text/javascript" >
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <div id=/ " pluginDiv/ " style=/ " display:none/ " ></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML = ' < object id = " objectForDetectPlugin " classid = " CLSID:'+ CLSID +' " ></ object > ';
try
{
if (eval( " objectForDetectPlugin. " + functionName) == undefined)
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return false ;
}
else
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return true ;
}
}
catch (e)
{
return false ;
}
}
function check()
{
if (detectPlugin(document.all.txtCLSID.value,document.all.txtFunctionName.value))
alert('该控件已经安装')
else
alert('该控件未安装');
}
</ script >
</ HEAD >
< BODY >
CLSID: < INPUT TYPE ="text" NAME ="txtCLSID" id ="txtCLSID" value ="22D6F312-B0F6-11D0-94AB-0080C74C7E95" > 属性或方法: < INPUT TYPE ="text" NAME ="txtFunctionName" id ="txtFunctionName" value ="AutoStart" >
< br >< INPUT TYPE ="submit" value ="判断" onclick ="check();return false;" >
< BODY >
</ HTML >
< HEAD >
< script type ="text/javascript" >
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <div id=/ " pluginDiv/ " style=/ " display:none/ " ></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML = ' < object id = " objectForDetectPlugin " classid = " CLSID:'+ CLSID +' " ></ object > ';
try
{
if (eval( " objectForDetectPlugin. " + functionName) == undefined)
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return false ;
}
else
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return true ;
}
}
catch (e)
{
return false ;
}
}
function check()
{
if (detectPlugin(document.all.txtCLSID.value,document.all.txtFunctionName.value))
alert('该控件已经安装')
else
alert('该控件未安装');
}
</ script >
</ HEAD >
< BODY >
CLSID: < INPUT TYPE ="text" NAME ="txtCLSID" id ="txtCLSID" value ="22D6F312-B0F6-11D0-94AB-0080C74C7E95" > 属性或方法: < INPUT TYPE ="text" NAME ="txtFunctionName" id ="txtFunctionName" value ="AutoStart" >
< br >< INPUT TYPE ="submit" value ="判断" onclick ="check();return false;" >
< BODY >
</ HTML >