Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript来确定设备类型IOS或Android以及shodiv依赖于此_Javascript_Android_Jquery_Html_Iphone - Fatal编程技术网

Javascript来确定设备类型IOS或Android以及shodiv依赖于此

Javascript来确定设备类型IOS或Android以及shodiv依赖于此,javascript,android,jquery,html,iphone,Javascript,Android,Jquery,Html,Iphone,下面是我的代码我需要做的是如果手机androd显示ANDROID_用户div如果iphone显示IOS_用户div一次只“第一次访问”每件事都以正确的方式工作但当我使用它时 <head> <style> #IOS_USERS { display: block; display:none; } #ANDROID_USERS

下面是我的代码我需要做的是如果手机androd显示ANDROID_用户div如果iphone显示IOS_用户div一次只“第一次访问”每件事都以正确的方式工作但当我使用它时

    <head>
    <style>
            #IOS_USERS {
                display: block;
                display:none;
            }

            #ANDROID_USERS {
                display: block;
                display:none;
            }

    </style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
//check mobile type
var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }

};

            function setCookie(cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                var expires = "expires=" + d.toGMTString();
                document.cookie = cname + "=" + cvalue + "; " + expires;
            }


            function getCookie(cname) {
                var name = cname + "=";
                var ca = document.cookie.split(';');
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i].trim();
                    if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
                }
                return "";
            }

            function MarkVisited() {
                setCookie("visited", "visited", 10)
            }

            function ClearCookie(cname) {
                setCookie(cname, "", 1)
            }



            $(document).ready(function() {

                 if (getCookie('visited') == "" && isMobile.iOS()) {
                    $('#ANDROID_USERS').hide();
                    $('#IOS_USERS').show();
                }
                else if (getCookie('visited') == "" && isMobile.Android()) {
                    $('#ANDROID_USERS').show();
                    $('#IOS_USERS').hide();
                }
                MarkVisited();
            });
</script>
    </head>
    <body>

        <div id="IOS_USERS">
         IOS 
        </div>
        <div id="ANDROID_USERS">
         ANDROID 
        </div>
        <button id="ClearCookie" onClick="ClearCookie('visited')">Clear Cookie</button>
    </body>

</html>
它没有以正确的方式检查手机类型 我需要知道我是否以正确的方式检查手机类型?

    <head>
    <style>
            #IOS_USERS {
                display: block;
                display:none;
            }

            #ANDROID_USERS {
                display: block;
                display:none;
            }

    </style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
//check mobile type
var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }

};

            function setCookie(cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                var expires = "expires=" + d.toGMTString();
                document.cookie = cname + "=" + cvalue + "; " + expires;
            }


            function getCookie(cname) {
                var name = cname + "=";
                var ca = document.cookie.split(';');
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i].trim();
                    if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
                }
                return "";
            }

            function MarkVisited() {
                setCookie("visited", "visited", 10)
            }

            function ClearCookie(cname) {
                setCookie(cname, "", 1)
            }



            $(document).ready(function() {

                 if (getCookie('visited') == "" && isMobile.iOS()) {
                    $('#ANDROID_USERS').hide();
                    $('#IOS_USERS').show();
                }
                else if (getCookie('visited') == "" && isMobile.Android()) {
                    $('#ANDROID_USERS').show();
                    $('#IOS_USERS').hide();
                }
                MarkVisited();
            });
</script>
    </head>
    <body>

        <div id="IOS_USERS">
         IOS 
        </div>
        <div id="ANDROID_USERS">
         ANDROID 
        </div>
        <button id="ClearCookie" onClick="ClearCookie('visited')">Clear Cookie</button>
    </body>

</html>

#IOS_用户{
显示:块;
显示:无;
}
#安卓用户{
显示:块;
显示:无;
}
//检查手机类型
var isMobile={
Android:function(){
返回navigator.userAgent.match(/Android/i);
},
黑莓:函数(){
返回navigator.userAgent.match(/BlackBerry/i);
},
iOS:function(){
返回navigator.userAgent.match(/iPhone/i);
},
Opera:函数(){
返回navigator.userAgent.match(/Opera-Mini/i);
},
Windows:function(){
返回navigator.userAgent.match(/IEMobile/i);
},
any:function(){
返回(isMobile.Android()| | isMobile.BlackBerry()| | isMobile.iOS()| | isMobile.Opera()| | isMobile.Windows());
}
};
函数setCookie(cname、cvalue、exdays){
var d=新日期();
d、 设置时间(d.getTime()+(exdays*24*60*60*1000));
var expires=“expires=“+d.togmString();
document.cookie=cname+“=”+cvalue+”;“+expires;
}
函数getCookie(cname){
变量名称=cname+“=”;
var ca=document.cookie.split(“;”);
对于(变量i=0;i
基于设备操作系统,您可以为Android和Iphone使用单独的css。您可以加载css,这是处理css的最佳方式。

你能说得更具体一点吗?我想测试一下我的代码,看看它是否能正常工作?在“联机”中,将用户代理添加到浏览器并进行检查。请检查我的问题,我更新了它,但仍在工作途中检查手机请检查我的问题
    <head>
    <style>
            #IOS_USERS {
                display: block;
                display:none;
            }

            #ANDROID_USERS {
                display: block;
                display:none;
            }

    </style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
//check mobile type
var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }

};

            function setCookie(cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                var expires = "expires=" + d.toGMTString();
                document.cookie = cname + "=" + cvalue + "; " + expires;
            }


            function getCookie(cname) {
                var name = cname + "=";
                var ca = document.cookie.split(';');
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i].trim();
                    if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
                }
                return "";
            }

            function MarkVisited() {
                setCookie("visited", "visited", 10)
            }

            function ClearCookie(cname) {
                setCookie(cname, "", 1)
            }



            $(document).ready(function() {

                 if (getCookie('visited') == "" && isMobile.iOS()) {
                    $('#ANDROID_USERS').hide();
                    $('#IOS_USERS').show();
                }
                else if (getCookie('visited') == "" && isMobile.Android()) {
                    $('#ANDROID_USERS').show();
                    $('#IOS_USERS').hide();
                }
                MarkVisited();
            });
</script>
    </head>
    <body>

        <div id="IOS_USERS">
         IOS 
        </div>
        <div id="ANDROID_USERS">
         ANDROID 
        </div>
        <button id="ClearCookie" onClick="ClearCookie('visited')">Clear Cookie</button>
    </body>

</html>