用js判断操做系统和浏览器类型

判断操做系统和浏览器的js代码linux

  navigator.userAgent:userAgent 属性是一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值。
    navigator.platform:platform 属性是一个只读的字符串,声明了运行浏览器的操做系统和(或)硬件平台。
   android

 

判断操做系统类型
win操做系统chrome

1     navigator.platform == "Win32"
2     navigator.platform == "Windows"

    win2000操做系统浏览器

1 /Windows NT 5.0/i.test(navigator.userAgent)

    WinXP操做系统微信

1 /Windows NT 5.1/i.test(navigator.userAgent)

    Win2003操做系统
       spa

1 /Windows NT 5.2/i.test(navigator.userAgent)

    WinVista操做系统操作系统

1  /Windows NT 6.0/i.test(navigator.userAgent)

    Win7操做系统firefox

1 /Windows NT 6.1/i.test(navigator.userAgent)

mac操做系统代理

1     navigator.platform == "Mac68K"
2     navigator.platform == "MacPPC"
3     navigator.platform == "Macintosh"
4     navigator.platform == "MacIntel"

unix操做系统unix

1 navigator.platform == "X11"

linux操做系统

1 /Linux/i.test(navigator.userAgent)

andorid操做系统

1     if(/Linux/i.test(navigator.userAgent)){
2         if(/android/i.test(navigator.userAgent.toLowerCase())){
3             return "android";
4         }
5     }

 




判断浏览器类型
    ie浏览器:

1 /ie/i.test(navigator.userAgent.toLowerCase());

    firefox浏览器

1 /firefox/i.test(navigator.userAgent.toLowerCase());

    谷歌浏览器

1 /chrome/i.test(navigator.userAgent.toLowerCase());

    opera浏览器

1 /opera/i.test(navigator.userAgent.toLowerCase());

    safari浏览器

1  /safari/i.test(navigator.userAgent.toLowerCase());

  微信浏览器

1 /micromessenger/i.test(navigator.userAgent.toLowerCase());
相关文章
相关标签/搜索