zoukankan      html  css  js  c++  java
  • 检测浏览器是否存在某个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;
            }
    

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

    我站在山顶看风景!下面是我的家乡!
  • 相关阅读:
    stack计算表达式的值
    stack例子
    stoi的例子
    前端 获取项目根路径的四种方式
    document.write()
    动态引入js文件
    Uncaught SyntaxError: Invalid or unexpected token
    oracle 快速备份表数据
    Tsinsen A1303. tree(伍一鸣) LCT
    VS2015--win32project配置的一些想法之cmake
  • 原文地址:https://www.cnblogs.com/zhensg123/p/14735059.html
Copyright © 2011-2022 走看看