zoukankan      html  css  js  c++  java
  • js 判断设备

    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;
                os.Mobile = userAgent.match(/Mobile/) ? true : false;    
                os.Nokia = userAgent.match(/Nokia/) ? true : false;    
                os.SAMSUNG = userAgent.match(/SAMSUNG/) ? true : false;    
                os.SonyEricsson = userAgent.match(/SonyEricsson/) ? true : false;    
                os.MOT = userAgent.match(/MOT/) ? true : false;    
                os.BlackBerry = userAgent.match(/BlackBerry/) ? true : false;    
                os.LG = userAgent.match(/LG/) ? true : false;        
                os.HTC = userAgent.match(/HTC/) ? true : false;        
                os.OperaMini = userAgent.match(/Opera Mini/) ? true : false;        
                os.UCWEB = userAgent.match(/UCWEB/) ? true : false;        
    
                os.isMobile = os.Mobile || os.Nokia || os.SAMSUNG || os.SonyEricsson || os.MOT ||
                        os.BlackBerry || os.LG || os.HTC || os.OperaMini || os.UCWEB;
                os.desktop = !os.isMobile;
                if(mobileUrl && os.isMobile){
                      window.location.href = mobileUrl;
                }

    参考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).*OSs([d_]+)/) ? true : false;
                os.ipod = userAgent.match(/(iPod).*OSs([d_]+)/) ? true : false;
                os.iphone = !os.ipad && userAgent.match(/(iPhonesOS)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;
                }
  • 相关阅读:
    显著提升程序员身心健康和工作效率的装备有哪些?
    谁控制了我们的浏览器?
    利用Http Authentication Url+csrf劫持路由器DNS
    如​何​删​除​G​P​T​保​护​分​区
    Linux定时器的使用
    缺少 mcrypt 扩展。请检查 PHP 配置。(phpmyadmin)
    xxx is not in the sudoers file
    linux mysql 找不到 <mysql/mysql.h>
    C++面试常见问题(持续更新)
    代码模板(new)
  • 原文地址:https://www.cnblogs.com/bandbandme/p/6755174.html
Copyright © 2011-2022 走看看