답변:
그것을보십시오 : http://davidwalsh.name/detect-android
자바 스크립트 :
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
// Do something!
// Redirect to Android-site?
window.location = 'http://android.davidwalsh.name';
}
PHP :
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
header('Location: http://android.davidwalsh.name');
exit();
}
편집 : 일부 의견에서 지적했듯이 이는 99 %의 경우에서 작동하지만 일부 가장자리 사례는 다루지 않습니다. JS에서 훨씬 더 진보 된 방탄 솔루션이 필요하다면 platform.js를 사용해야합니다 : https://github.com/bestiejs/platform.js
var isAndroid = /Android/i.test(navigator.userAgent)
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 625; Orange) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
이 한 줄짜리는 어때?
var isAndroid = /(android)/i.test(navigator.userAgent);
i개질제는 대소 문자 구별 매칭을 수행하기 위해 사용된다.
Cordova AdMob 테스트 프로젝트에서 가져온 기술 : https://github.com/floatinghotpot/cordova-admob-pro/wiki/00.-How-To-Use-with-PhoneGap-Build
Michal의 답변이 최고라고 생각하지만 한 단계 더 나아가 원래 질문에 따라 Android CSS를 동적으로로드 할 수 있습니다.
var isAndroid = /(android)/i.test(navigator.userAgent);
if (isAndroid) {
var css = document.createElement("link");
css.setAttribute("rel", "stylesheet");
css.setAttribute("type", "text/css");
css.setAttribute("href", "/css/android.css");
document.body.appendChild(css);
}
;(function() {
var redirect = false
if (navigator.userAgent.match(/iPhone/i)) {
redirect = true
}
if (navigator.userAgent.match(/iPod/i)) {
redirect = true
}
var isAndroid = /(android)/i.test(navigator.userAgent)
var isMobile = /(mobile)/i.test(navigator.userAgent)
if (isAndroid && isMobile) {
redirect = true
}
if (redirect) {
window.location.replace('jQueryMobileSite')
}
})()
Node.js 버전, iPad도 잡습니다.
var is_mobile = /mobile|android/i.test (navigator.userAgent);