zoukankan      html  css  js  c++  java
  • 用js判断操作系统和浏览器类型

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

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

    判断操作系统类型
    win操作系统

    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操作系统
           

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

        WinVista操作系统

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

        Win7操作系统

    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操作系统

    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());



  • 相关阅读:
    第八周总结和实验六
    第七周总结与实验五
    遍历目录中的所有文件和目录,并生成全路径
    python watchdog
    Offer_answer_with_SDP_rfc3264
    [转]UML八大误解
    leetcode周赛220
    Codeforces Round #690 (Div. 3)
    学习资料
    鱼眼图与六面图转换(python)
  • 原文地址:https://www.cnblogs.com/sustudy/p/4241053.html
Copyright © 2011-2022 走看看