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;
        }
  • 相关阅读:
    【PAT甲级】1054 The Dominant Color
    【PAT甲级】1001 A+B Format
    【算法】二分排序和二分查找
    【PAT甲级】1008 Elevator (20分)
    移动端工作准备
    媒体查询
    多列布局
    怪异盒模型
    弹性盒
    圆角
  • 原文地址:https://www.cnblogs.com/huzhuhua/p/12376307.html
Copyright © 2011-2022 走看看