如何判断客户端是否安装了指定的ActiveX控件

本文提供了一种方法来检测浏览器中是否已安装特定的插件。通过创建一个隐藏的HTML元素并尝试加载指定插件,可以判断插件是否可用。此方法适用于第三方组件,弥补了DHTMLBehavior中isComponentInstalled方法的局限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何判断客户端是否安装了某个插件?最常见的就是使用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个小时写了下面通用的方法,供大家参考:
< HTML >
< HEAD >
< script type ="text/javascript" >
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <divid=/ " pluginDiv/ " style=/ " display:none/ " ></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML
= ' < objectid = " 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();returnfalse;" >
< BODY >
</ HTML >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值