码迷,mamicode.com
首页 > Web开发 > 详细

js 判断设备

时间:2017-04-24 09:57:17      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:ceo   sam   eof   location   mat   smo   playbook   webos   black   

varnish判断

 

 if (req.http.User-Agent ~ "Mobile"
        || req.http.User-Agent ~ "Nokia"
        || req.http.User-Agent ~ "SAMSUNG"
        || req.http.User-Agent ~ "SonyEricsson"
        || req.http.User-Agent ~ "MOT"
        || req.http.User-Agent ~ "BlackBerry"
        || req.http.User-Agent ~ "LG"
        || req.http.User-Agent ~ "HTC"
        || req.http.User-Agent ~ "J2ME"
        || req.http.User-Agent ~ "Opera Mini"
        || req.http.User-Agent ~ "UCWEB"
    ) {
        set req.http.internal.isMobile = "true";
    }

 

js判断

var os = {},userAgent = window.navigator.userAgent,isToM;
            os.webkit = userAgent.match(/WebKit\/([\d.]+)/) ? true : false;
            os.webkit = userAgent.match(/WebKit\/([\d.]+)/) ? true : false;
            os.android = userAgent.match(/(Android)\s+([\d.]+)/) || userAgent.match(/Silk-Accelerated/) ? true : false;
            os.androidICS = os.android && userAgent.match(/(Android)\s4/) ? true : false;
            os.ipad = userAgent.match(/(iPad).*OS\s([\d_]+)/) ? true : false;
            os.ipod = userAgent.match(/(iPod).*OS\s([\d_]+)/) ? true : false;
            os.iphone = !os.ipad && userAgent.match(/(iPhone\sOS)\s([\d_]+)/) ? true : false;
            os.webos = userAgent.match(/(webOS|hpwOS)[\s\/]([\d.]+)/) ? true : false;
            os.touchpad = os.webos && userAgent.match(/TouchPad/) ? true : false;
            os.ios = os.ipad || os.iphone;
            os.ios6 = os.ios &&  userAgent.match(/(OS)\s([6])/) ? true : false;
            os.playbook = userAgent.match(/PlayBook/) ? true : false;
            os.blackberry = os.playbook || userAgent.match(/BlackBerry/) ? true : false;
            os.blackberry10 = os.blackberry && userAgent.match(/Safari\/536/) ? true : false;
            os.chrome = userAgent.match(/Chrome/) ? true : false;
            os.opera = userAgent.match(/Opera Mobi/) ? true : false;
            os.fennec = userAgent.match(/fennec/i) ? true : false;
            os.supportsTouch = ((window.DocumentTouch && document instanceof window.DocumentTouch) || ‘ontouchstart‘ in window);
            os.desktop = !(os.ios || os.android || os.blackberry || os.opera || os.fennec || os.supportsTouch);

            if(mobileUrl && (os.ipod || os.iphone || os.android)){
                  window.location.href = mobileUrl;
            }

 

js 判断设备

标签:ceo   sam   eof   location   mat   smo   playbook   webos   black   

原文地址:http://www.cnblogs.com/bandbandme/p/6755174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!