function isAndroid(){
var device = {};
var ua = navigator.userAgent;
var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
device.android = false;
if (android) {
device.android = true;
}
return device;
}
同理可用以下正则替换判断其他类型:
var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
时间: 2024-10-06 13:26:18