• 检测浏览器是否存在某个css或者js的api


    利用能力检测检测是否存在某个js的api

          // 检测是否存在某个api
            function isHostMethod(object, property){
              let t = typeof object[property]
              return  t == 'function' || (!!(t=='object' && object[property])) || t == 'unknowns'
            }
            let xhr = new ActiveXObject('Microsoft.XMLHttp')
            // 比如检测xhr是否存在open
            isHostMethod(xhr,'open')
    

      利用能力检测检测是否存在某个属性

        function supportCss3(style) {
                // 分别是google Safari ie
                var prefix = ['webkit', 'Moz', 'ms'],
                    i,
                    humpString = [],
                    htmlStyle = document.documentElement.style,
                    _toHumb = function (string) {
                        return string.replace(/-(w)/g, function ($0, $1) {
                            return $1.toUpperCase();
                        });
                    };
    
                for (i in prefix) {
                    humpString.push(_toHumb(prefix[i] + '-' + style));
                    humpString.push(_toHumb(style));
                }
    
    
                for (i in humpString) {
                    if (humpString[i] in htmlStyle) {
                        return true
                    }
                }
    
                return false;
            }
    

      作为开发人员都是在一定能力范围内,浏览器的能力范围内搞开发的。能力检测可以检测浏览器是否具备这种能力。

    我站在山顶看风景!下面是我的家乡!
  • 相关阅读:
    squid代理缓存服务
    部署网络存储ISCSI
    电子邮局系统
    使用DHCP动态管理主机地址
    vsftp -samba-autofs
    python初学 | 循环for while
    python初学 | 条件语句if
    python初学 | set
    python初学 | 字典dictionary
    python初学 | 元组tuple
  • 原文地址:https://www.cnblogs.com/zhensg123/p/14735059.html
Copyright © 2020-2023  润新知