所有我需要知道的是,如果我以正確的方式檢查移動類型? 還有其他方法來檢查移動類型?檢查移動類型是否正確? 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