如何判断客户端的某个插件是否安装

近日遇到了一些问题,即如何判断客户端是否安装了某个插件、版本是否达到了我们的要求?最常见的就是使用DHTML Behavior中的两个方法:isComponentInstalled和getComponentVersion。
我们先看看msdn上关于这两个方法的说明:
http://msdn.microsoft.com/…/iscomponentinstalled.asp?frame=true
http://msdn.microsoft.com/…/getcomponentversion.asp?frame=true

代码示例:

<span style="behavior:url(#default#clientCaps)" id="info"></span>

<
script type="text/javascript">
function 
detectPlugin(sID)
{
    var 
bComInstalled info.isComponentInstalled(sID"ComponentID");
    if (
bComInstalled)
    {
        return 
"已安装。版本号:" info.getComponentVersion(sID"ComponentID");
    }
    else
    {
        return 
"未安装.";
    }
}

alert("Flash插件" detectPlugin("{D27CDB6E-AE6D-11CF-96B8-444553540000}"));

/*
ClassID list

{CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA}       RealMedia
{6BF52A52-394A-11D3-B153-00C04F79FAA6}       WindowsMedia version >=7
{22D6F312-B0F6-11D0-94AB-0080C74C7E95}       WindowsMedia version 6.4
{02BF25D5-8C17-4B23-BC80-D3488ABDDC6B}       QuickTime
{D27CDB6E-AE6D-11CF-96B8-444553540000}       Flash
*/

</script> 

这样虽然能够检测出大部分的常见插件,但是一些第三方插件,这种方法好像是不可行的。
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.

我尝试了如下的方法:

<div id="info" style="display:none"></div>
<
script type="text/javascript">
function 
detectPlugin(sID)
{
    var 
pVersion;
    
info.innerHTML '<object id="webCtrl" classid="CLSID:'sID +'"></object>';
    try
    {
        
pVersion webCtrl.getVersion();  //控件内自己定义的一个返回版本号的方法
        //return "v:" + pVersion;
        
return true;
    }
    catch (
e)
    {
        return 
false;
    }
}
</script> 

这样虽然基本满足了我的要求,不过老是觉得这种方法走了弯路。最近的项目里用到这个,不知道各位有什么更好的方法,望不吝赐教。

13 Comments »

  1. 瑞柯坤泰 said,

    April 7, 2005 @ 8:47 am

    以前看过类似的文章,这种解决方案还不错!

  2. andot said,

    April 12, 2005 @ 12:37 pm

    erik说innerHTML是有害的:
    http://erik.eae.net/archives/2005/04/08/18.13.31/

  3. legend said,

    April 13, 2005 @ 12:26 am

    那用虾米…

  4. andot said,

    April 13, 2005 @ 9:13 am

    用createElement啊。

  5. 避雷器 said,

    December 20, 2005 @ 6:23 am

    用createElement

  6. play craps said,

    June 1, 2006 @ 9:19 pm

    Consider pairs support up cut ragged play craps push http://www.ohiosteelbuildings.com/play-craps center buy chip score?

  7. blackjack online said,

    June 1, 2006 @ 10:21 pm

    Offer neutral neutral base pushka blackjack online bonuses crown push pineapple management hand http://www.norpen.com/blackjack-online bible insurance!

  8. online no fax payday loan said,

    June 2, 2006 @ 4:02 am

    Two exotic no broadway check online no fax payday loan support fold surrender http://www.richplancorp.com/online-no-fax-payday-loan scalper high bullets spread!

  9. diet pills said,

    December 21, 2006 @ 10:57 am

    innocently Cinerama refraction planking,Englishmen extorted tickled amending

  10. buy diet pills said,

    December 22, 2006 @ 12:04 pm

    interdependence.funereal slams electrolytes lightface one schoolhouses

  11. diet pills said,

    December 25, 2006 @ 6:56 am

    U’ve got good pics, the site could use a tiny bit of work (no offense) its still awesome

  12. Regence said,

    January 11, 2007 @ 7:10 pm

    We loved the site, really loved it!

  13. Aracelis said,

    February 5, 2014 @ 5:54 pm

    I enjoy, result in I discovered exactly what I was looking for.
    You have ended my 4 day long hunt! God Bless you
    man. Have a great day. Bye

RSS feed for comments on this post

Leave a Comment