zoukankan      html  css  js  c++  java
  • 移动设备判断方法大全


    Demo_1

    
    function isMobile(){
        if (typeof this._isMobile === 'boolean'){
            return this._isMobile;
        }
        var screenWidth = this.getScreenWidth();
        var fixViewPortsExperiment = rendererModel.runningExperiments.FixViewport ||rendererModel.runningExperiments.fixviewport;
        var fixViewPortsExperimentRunning = fixViewPortsExperiment && (fixViewPortsExperiment.toLowerCase() === "new");
        if(!fixViewPortsExperiment){
            if(!this.isAppleMobileDevice()){
                screenWidth = screenWidth/window.devicePixelRatio;
            }
        }
        var isMobileScreenSize = screenWidth < 600;
        var isMobileUserAgent = false;
        this._isMobile = isMobileScreenSize && this.isTouchScreen();
        return this._isMobile;
    }
    
    


    Demo_2

    
    function isMobileUserAgent(){
        return (/iphone|ipod|android.*mobile|windows.*phone|blackberry.*mobile/i.test(window.navigator.userAgent.toLowerCase()));
    }
    
    


    判断是否苹果移动设备访问

    
    function isAppleMobileDevice(){
        return (/iphone|ipod|ipad|Macintosh/i.test(navigator.userAgent.toLowerCase()));
    }
    
    


    判断是否安卓移动设备访问

    
    function isAndroidMobileDevice(){
        return (/android/i.test(navigator.userAgent.toLowerCase()));
    }
    
    


    判断是否Touch屏幕

    
    function isTouchScreen(){
        return (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
    }
    
    
  • 相关阅读:
    洛谷P3747 [六省联考2017]相逢是问候
    染色(dye)
    BZOJ1426: 收集邮票
    消息队列RabbitMQ
    CRM
    BBS
    版本控制
    RESTful API
    Luffy
    axios使用
  • 原文地址:https://www.cnblogs.com/lalalagq/p/10207819.html
Copyright © 2011-2022 走看看