判断机型版本号

         var os = {};
        // The  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;
        }

你可能感兴趣的:(判断机型版本号)