• 浏览器识别操作系统


    前端识别操作系统


    @软件设计模式概述

    浏览器识别操作系统

    <html>
    
    <head>
      <title>Judge System Ostitle>
      <script type="text/javascript">
        function detectOS() {
          var sUserAgent = navigator.userAgent;
          var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
          var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
          if (isMac) return "Mac";
          var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
          if (isUnix) return "Unix";
          var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
          var bIsAndroid = sUserAgent.toLowerCase().match(/android/i) == "android";
          if (isLinux) {
            if (bIsAndroid) return "Android";
            else return "Linux";
          }
          if (isWin) {
            var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
            if (isWin2K) return "Win2000";
            var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 ||
              sUserAgent.indexOf("Windows XP") > -1;
            if (isWinXP) return "WinXP";
            var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
            if (isWin2003) return "Win2003";
            var isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
            if (isWinVista) return "WinVista";
            var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
            if (isWin7) return "Win7";
          }
    
          if (sUserAgent.indexOf("Windows NT 8") != -1) {
            return "win8";
    
          }
    
          if (sUserAgent.indexOf("Windows NT 10") != -1) {
            return "win10";
    
          }
    
          return "other";
        }
        // document.writeln("您的操作系统是:" + detectOS());
      script>
      <script>
        var osData = [
          { name: 'Windows 2000', group: 'windows_server', identifier: 'Windows NT 5.0', version: '5.0' },
          { name: 'Windows XP', group: 'windows', identifier: 'Windows NT 5.1', version: '5.1' },
          { name: 'Windows 2003', group: 'windows_server', identifier: 'Windows NT 5.2', version: '5.2' },
          { name: 'Windows Vista', group: 'windows', identifier: 'Windows NT 6.0', version: '6.0' },
          { name: 'Windows 7', group: 'windows', identifier: 'Windows NT 6.1', version: '7.0' },
          { name: 'Windows 8', group: 'windows', identifier: 'Windows NT 6.2', version: '8.0' },
          { name: 'Windows 8.1', group: 'windows', identifier: 'Windows NT 6.3', version: '8.1' },
          { name: 'Windows 10', group: 'windows', identifier: 'Windows NT 10.0', version: '10.0' },
          { name: 'Windows 2008', group: 'windows_server', identifier: 'Windows NT 6.0; WOW64', version: '6.0' },
          { name: 'Windows 2008', group: 'windows_server', identifier: 'Windows NT 6.1; WOW64', version: '6.1' },
          { name: 'Windows 2012', group: 'windows_server', identifier: 'Windows NT 6.3; Win64', version: '6.3' },
          { name: 'Chrome OS', group: 'windows', identifier: 'CrOS' },
          { name: 'Mac OS X Capitan', group: 'mac', identifier: 'Mac OS X (10([_|\.])11([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Yosemite', group: 'mac', identifier: 'Mac OS X (10([_|\.])10([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Mavericks', group: 'mac', identifier: 'Mac OS X (10([_|\.])9([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Mountain Lion', group: 'mac', identifier: 'Mac OS X (10([_|\.])8([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Lion', group: 'mac', identifier: 'Mac OS X (10([_|\.])7([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Snow Leopard', group: 'mac', identifier: 'Mac OS X (10([_|\.])6([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Leopard', group: 'mac', identifier: 'Mac OS X (10([_|\.])5([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Tiger', group: 'mac', identifier: 'Mac OS X (10([_|\.])4([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Panther', group: 'mac', identifier: 'Mac OS X (10([_|\.])3([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Jaguar', group: 'mac', identifier: 'Mac OS X (10([_|\.])2([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Puma', group: 'mac', identifier: 'Mac OS X (10([_|\.])1([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS X Cheetah', group: 'mac', identifier: 'Mac OS X (10([_|\.])0([0-9_\.]*))', versionSeparator: '[_|\.]' },
          { name: 'Mac OS', group: 'mac', identifier: 'Mac OS' },
          { name: 'Ubuntu', group: 'linux_server', identifier: 'Ubuntu', versionIdentifier: 'Ubuntu/([0-9\.]*)' },
          { name: 'CentOs', group: 'linux_server', identifier: 'CentOs', versionIdentifier: 'CentOs/([0-9\.]*)' },
          { name: 'Debian', group: 'linux_server', identifier: 'Debian' },
          { name: 'Gentoo', group: 'linux_server', identifier: 'Gentoo' },
          { name: 'GCH-System', group: 'linux', identifier: 'Linux' }
        ];
        var setOsData = function (os) {
          var userAgent = navigator.userAgent.toLowerCase();
          // Check browser type
          for (i in osData) {
            if (osData.hasOwnProperty(i)) {
              var osRegExp = new RegExp(osData[i].identifier.toLowerCase());
              var osRegExpResult = osRegExp.exec(userAgent);
    
              if (osRegExpResult != null) {
                os.name = osData[i].name;
                os.group = osData[i].group;
                break;
              }
            }
          }
    
          return true;
        };
        var setOsVersion = function (os, version, separator) {
          if (separator.substr(0, 1) == '[') {
            var splitVersion = version.split(new RegExp(separator, 'g'), 2);
          } else {
            var splitVersion = version.split(separator, 2);
          }
          if (separator != '.') {
            version = version.replace(new RegExp(separator, 'g'), '.');
          }
          os.fullVersion = version;
          // Major version
          if (splitVersion[0]) {
            os.majorVersion = parseInt(splitVersion[0]);
          }
          // Minor version
          if (splitVersion[1]) {
            os.minorVersion = parseInt(splitVersion[1]);
          }
    
          return true;
        };
        var os = {};
        setOsData(os);
        document.writeln("Your Current System OS is:" + os.name);
      script>
    head>
    
    <body>
    body>
    
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
  • 相关阅读:
    spark 与 mapreduce 对比
    学习MySQL必须掌握的13个关键字,你get了吗?
    【实验】配置用户自动获取IPv6地址的案例
    点击弹窗页面右侧缩小问题
    webpack-bundle-analyzer 打包分析工具
    做FP还不了解怎样建站?一文讲懂独立站搭建与选择
    HTML如何制作公司网站首页(web前端期末大作业)
    Rust 泛型
    XTU-OJ 1247-Robb‘s Problem
    opensd开源啦 ,这套自动化部署OpenStack工具你值得拥有
  • 原文地址:https://blog.csdn.net/weixin_43862492/article/details/126248634