首页 > 移动端网站开发碰见的问题,怎么通过window对象是分辨是安卓系统的还是iOS系统的办法

移动端网站开发碰见的问题,怎么通过window对象是分辨是安卓系统的还是iOS系统的办法

有没有哪个大神知道用JS获取当前访问这个页面的手机是安卓的还是IOS的办法呀? 跪求,在线等,貌似window对象并没有提供这样一个功能吧


你可以通过正则表达式判断window.navigator.userAgent


    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 

// JavaScript Document
//判断手机系统

window.onload = function () {
    var u = navigator.userAgent;
    if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
        alert("安卓手机");
    }
     //else
    if (u.indexOf('iPhone') > -1) {//苹果手机
       alert("苹果手机");
    } ;
};
【热门文章】
【热门文章】