zoukankan      html  css  js  c++  java
  • 原生JS检测浏览器安装的插件

    navigator里面有plugins 这个属性就是用来检测浏览器插件的。plugins 返回的结果 是一个数组形式。
    该数组中的每一项都包含下列属性。
     name :插件的名字。
     description :插件的描述。
     filename :插件的文件名。
     length :插件所处理的 MIME 类型数量

    例子如下:

    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;
    }
    //检测 Flash
    if(hasPlugin("Flash")){
      alert('你的浏览器有flash插件')
    };

     IE 不支持 Netscape 式的插件。在 IE 中检测插件的唯一方式就是使用专有的 ActiveXObject 类型

        //检测 IE 中的插件
        function hasIEPlugin(name) {
            try {
                new ActiveXObject(name);
                return true;
            } catch (ex) {
                return false;
            }
        }
        //检测 Flash
        alert(hasIEPlugin("ShockwaveFlash.ShockwaveFlash"));

    然后封装下就可以了

        function hasPlugins(name) {
            name = name.toLowerCase();
            let result = false;
            for (var i = 0; i < navigator.plugins.length; i++) {
                if (navigator.plugins[i].name.toLowerCase().indexOf(name) > -1) {
                    result = true
                }
            }
            if (!result) {
                try {
                    new ActiveXObject(name);
                    result = true;
                } catch (ex) {
                    result = false;
                }
            }
            return result;
        }
  • 相关阅读:
    xUtils 中的BitmapUtils 全面注释
    321影音代码
    android studio使用技巧
    java android面试题分析总结
    android面试题分析总结
    据说年薪30万的Android程序员必须知道的帖子
    好用软件
    win10找回win7的windows照片查看器
    github上传代码
    android 常见错误集锦
  • 原文地址:https://www.cnblogs.com/huzhuhua/p/12376307.html
Copyright © 2011-2022 走看看