【JavaScript高级程序设计】14、BOM对象(2)

检查浏览器中的插件

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>

  <script type="text/javascript">
    
       //对于不是IE得浏览器,检查插件的方式是
        function hasPlugin(name)
        {
            name = name.toLowerCase();
            for (var i=0; i < navigator.plugins.length; i++)
            {
                if (navigator.plugins[i].name.toLowerCase().indexOf(name) > -1)
                {
                    return true;
                }
            }

            return false;
        }

        //是ie的话使用这个来检查
        function hasIEPlugin(name)
        {
            try 
            {
                //如果无法创建这个插件的实例,那么就会报异常
                //说明没有这个实例,说明没有这个插件
                new ActiveXObject(name);
                return true;
            } 
            catch (ex)
            {
                return false;
            }
        }

        //判断是否是ie
        var isIE=navigator.userAgent.toUpperCase().indexOf("MSIE")==-1?false:true;

        if(!isIE)
        {
            alert(hasPlugin("Flash") + "===>flash");
            alert(hasPlugin("QuickTime") + "===>QuickTime");
            alert(hasPlugin("Java") + "===>Java");
            
        }
        else
        {
            alert(hasIEPlugin("ShockwaveFlash.ShockwaveFlash") + "===>flash==>IE");    

            alert(hasIEPlugin("QuickTime.QuickTime") + "===>QuickTime===>IE");
        }

    </script>
 </head>
 <body>
  
 </body>
</html>

结果:

谷歌显示:

 

 

 ie中显示:

 

posted @ 2016-07-26 09:50  cutter_point  阅读(94)  评论(0)    收藏  举报