admin管理员组

文章数量:1530975

Navigator 对象:包含有关浏览器的信息,所有浏览器都支持该对象
对象属性参考:https://www.w3school/jsref/dom_obj_navigator.asp

属性描述
appCodeName返回浏览器的代码名。
appMinorVersion返回浏览器的次级版本。
appName返回浏览器的名称。
appVersion返回浏览器的平台和版本信息。
userAgent返回由客户机发送服务器的 user-agent 头部的值。

userAgent 属性是一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值
各个浏览器关于userAgent属性的值:
1、谷歌
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
2、火狐
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0
3、360极速模式
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
4、IE11 360兼容模式
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; rv:11.0) like Gecko
5、IE浏览器10
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0)
6、IE浏览器9
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0)
7、IE浏览器8
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0)
8、IE浏览器7
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0)
9、IE浏览器5
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0)

function myBrowsr(){
    var userAgent = navigator.userAgent.toLocaleLowerCase(); //取得浏览器的userAgent字符串并转换为小写
    //360浏览器,以往检测方式,现在360的usrAgent与谷歌返回一样,无法检测
    /*if( userAgent.indexOf("360ee") > -1 || userAgent.indexOf("360se") > -1 ){
        return "360"
    }*/
    //新检测,不确定是否100%检测出一定是360浏览器
    if( is360() ){
        return "360"
    }
    //谷歌浏览器
    if( userAgent.indexOf("chrome")>-1 && userAgent.indexOf("safari")>-1 && !is360() ){
        return "chrome"
    }
    //火狐浏览器
    if( userAgent.indexOf("firefox")>-1 ){
        return "firefox"
    }
    //欧朋浏览器
    if( userAgent.indexOf("opera")>-1 || userAgent.indexOf('opr') > -1 ){
        return "opera"
    }
    //safari浏览器
    if( userAgent.indexOf("safari")>-1 && userAgent.indexOf("chorome") === -1 && !is360() ){
        return "safar"
    }
    //IE11浏览器
    if( userAgent.indexOf("trident")>-1 && userAgent.indexOf("rv:11.0") > -1 ){
        return "ie11"
    }
    //IE浏览器
    if( userAgent.indexOf("compatible")>-1 && userAgent.indexOf("msie") > -1 ){
        return "ie"
    }
    //UC浏览器
    if( userAgent.indexOf("ucbrowser")>-1 && userAgent.indexOf("ubrowser") > -1 ){
        return "uc"
    }
    //微信浏览器
    if( userAgent.indexOf("micromessenger")>-1 ){
        return "wechat"
    }        
}
function is360(){
    var mType=navigator.mimeTypes;
    for(let i=0; i<mType.length;i++){
        if(mType[i].type.indexOf("360soft")>-1){
            return 1
        }else{
            return 0
        }
    }
}
console.log('我是'+myBrowsr()+'浏览器');
//判断系统
function myOS(){
    var userAgent = navigator.userAgent.toLocaleLowerCase(); //取得浏览器的userAgent字符串并转换为小写
    if( userAgent.indexOf( "compatible" )>-1 || userAgent.indexOf("windows")>-1 ){
        return 'windows';
    }else if( userAgent.indexOf("macintosh")>-1 && userAgent.indexOf("macintel")>-1){
        return "macOS";
    }else if( userAgent.indexOf("iphone")>-1 ){
        return "ios";
    }else if( userAgent.indexOf("android")>-1 ){
        return 'android';
    }else if(userAgent.indexOf('ipad')>-1){
        return 'ipad';
    }else{
        return "other";
    }
}
console.log('我是'+myOS()); 

本文标签: 型号器及版本手机