所有我需要知道的是,如果我以正确的方式检查移动类型? 还有其他方法来检查移动类型?检查移动类型是否正确? Javascript根据手机类型显示一个分区一次
请参阅下面的代码 我如何使用任何工具尝试它?
任何人都知道,检查移动类型正确的方式,如果IOS或低于我的代码ANDROID
<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>
可能的复制http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-一个手持设备在jquery和http://stackoverflow.com/questions/6031412/detect-android-phone-via-javascript-jquery – mguimard
我没有得到它如何我可以在我的代码中应用它? – user3469218