美文网首页
判断机型版本号

判断机型版本号

作者: web佳 | 来源:发表于2018-07-30 15:45 被阅读0次
             var os = {};
            // The <html> element.
            var documentElement = window.document.documentElement;
    
            // The client user agent string.
            // Lowercase, so we can use the more efficient indexOf(), instead of Regex
            var userAgent = window.navigator.userAgent.toLowerCase().split('amap/')[0];
    
            // Simple UA string search
            var find = function (needle) {
                return userAgent.indexOf(needle) !== -1;
            };
    
            // windows下浏览器
            os.windows = find('windows');
            os.iphone = !os.windows && find('iphone');
            os.ipod = find('ipod');
            os.ipad = find('ipad');
            os.ios = os.iphone || os.ipod || os.ipad;
            os.android = !os.windows && find('android');
            os.androidPhone = os.android && find('mobile');
            // 安卓平板
            os.androidTablet = os.android && !find('mobile');
    
    
            // Insert the appropriate CSS class based on the _user_agent.
            if (os.ios) {
                var v = userAgent.match(/(iphone|ipad|ipod).*?os\s([\d_]+)\s/i);
                os.version = v[2];
            } else if (os.android) {
                os.version = userAgent.substr(userAgent.indexOf('android') + 8, 3);
            }
            var match_version = os.version.replace(/\_/g, '.').match(/^\d+(?:\.\d+)?/);
            if (match_version) {
                os._version = match_version[0] * 1;
            } else {
                os._version = 0;
            }

    相关文章

      网友评论

          本文标题:判断机型版本号

          本文链接:https://www.haomeiwen.com/subject/otkgpftx.html