美文网首页
使用navigator.userAgent.toLowerCa

使用navigator.userAgent.toLowerCa

作者: 我只是一个小前端 | 来源:发表于2018-05-02 15:40 被阅读0次

    判断设备,区分Android,iphone,ipad和其它

    varua  = navigator.userAgent.toLowerCase();

    if(ua.match(/android/i)) =="android")

    {

    alert("android");

    }

    if(ua.match(/iPhone/i)) =="iPhone")

    {

    alert("iPhone");

    }

    if(ua.match(/iPad/i)) =="iPad")

    {

    alert("iPad");

    }

    判断是不是特定类型的浏览器,比如新浪weibo客户端内置浏览器,qq客户端内置浏览器(而非qq浏览器),微信内置浏览器

    (并且区分版本是否大于等于6.0.2)(特定类型浏览器可能会存在,无法下载,无法跳转和自己的客户端app的特定协议等等,所以需要区分)

    (由于微信在6.0.2的时候做了新的策略,使得微信的分享功能在新版本变得不一样,为了兼容新旧版本,这里做了区分操作)

    新浪weibo客户端返回1,qq客户端返回2,微信小于6.0.2版本返回3,微信大于等于6.0.2版本返回4,其它返回0

    varua = navigator.userAgent.toLowerCase();

    if(ua.match(/weibo/i) =="weibo"){

    return1;

    }elseif(ua.indexOf('qq/')!= -1){

    return2;

    }elseif(ua.match(/MicroMessenger/i)=="micromessenger"){

    varv_weixin = ua.split('micromessenger')[1];

    v_weixin = v_weixin.substring(1,6);

    v_weixin = v_weixin.split(' ')[0];

    if(v_weixin.split('.').length == 2){

    v_weixin = v_weixin +'.0';

    }

    if(v_weixin <'6.0.2'){

    return3;

    }else{

    return4;

    }

    }else{

    return0;

    }

    相关文章

      网友评论

          本文标题: 使用navigator.userAgent.toLowerCa

          本文链接:https://www.haomeiwen.com/subject/zwdyhxtx.html