我如何检测到正在使用的设备是用于移动网站的 Android 设备?
我需要将某些 css 属性应用到 Android 平台。
谢谢
最佳答案
看看那个:http://davidwalsh.name/detect-android
JavaScript:
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
关于javascript - 通过 Javascript/jQuery 检测 Android 手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6031412/