欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JS代码实现电脑配置检测功能

程序员文章站 2022-05-04 10:53:12
下面一段代码给大家分享js代码实现电脑配置检测功能,具体代码如下所示:

下面一段代码给大家分享js代码实现电脑配置检测功能,具体代码如下所示:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <style type="text/css">
    h1 {
      text-align: center;
      color: #000046;
    }
    .i {
      display: inline-block;
      vertical-align: middle;
      width: 30px;
      height: 30px;
      margin: 5px 20px;
      background: url(http://yi.sunlands.com/ent-portal-war/images/tc_icon.png) no-repeat;
    }
    .a {
      background-position: 0 0;
    }
    .b {
      background-position: 0 -40px;
    }
    .c {
      background-position: 0 -80px;
    }
    .d {
      background-position: 0 -120px;
    }
    .e {
      background-position: 0 -160px;
    }
    b {
      color: #007ac3;
      padding-right: 10px;
    }
    i {
      color: green;
      font-weight: bold;
    }
    .box {
      width: 460px;
      height: 360px;
      margin: auto;
      padding: 20px;
      border: 2px solid darkgray;
      font-size: 18px;
      border-radius: 10px;
      border-left-width: 10px;
      border-right-width: 10px;
    }
  </style>
  <body>
    <h1>电脑配置检测</h1>
    <hr />
    <div class="box">
      <p> <i class="i a"></i> <b>您的操作系统是: </b> <i id="xitong"></i> </p>
      <p> <i class="i b"></i> <b>您的网络链接状态是: </b> <i id="netline"></i> </p>
      <p> <i class="i b"></i> <b>您当前浏览网速是:</b> <i id="wangsu"></i> </p>
      <p> <i class="i c"></i> <b>您电脑的分辨率是:</b> <i id="fenbianlv"></i> </p>
      <p> <i class="i d"></i> <b>您的浏览器是:</b> <i id="liulanqi"></i> </p>
      <p> <i class="i e"></i> <b>您的flash的版本是:</b> <i id="flash_banben"></i> </p>
    </div>
  </body>
  <script src="jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
    $(function(){
      if(typeof obj == "undefined") {
        var obj = new object();
      }
      if(typeof obj.swfobjectutil == "undefined") {
        obj.swfobjectutil = new object();
      }
      obj.swfobject = function(_1, id, w, h, _5, c, _7, _8, _9, _a) {
        if(!document.getelementbyid) return;
        this.params = new object();
        this.variables = new object();
        this.attributes = new array();
        if(_1) this.setattribute("swf", _1);
        if(id) this.setattribute("id", id);
        if(w) this.setattribute("width", w);
        if(h) this.setattribute("height", h);
        if(_5) this.setattribute("version", new obj.playerversion(_5.tostring().split(".")));
        this.installedver = obj.swfobjectutil.getplayerversion();
        if(!window.opera && document.all && this.installedver.major > 7) {
          obj.swfobject.doprepunload = true;
        }
        if(c) this.addparam("bgcolor", c);
        var q = _7 ? _7 : "high";
        this.addparam("quality", q);
        this.setattribute("useexpressinstall", false);
        this.setattribute("doexpressinstall", false);
        var _c = (_8) ? _8 : window.location;
        this.setattribute("xiredirecturl", _c);
        this.setattribute("redirecturl", "");
        if(_9) this.setattribute("redirecturl", _9);
      };
      obj.swfobject.prototype = {
        useexpressinstall: function(_d) {
          this.xiswfpath = !_d ? "expressinstall.swf" : _d;
          this.setattribute("useexpressinstall", true);
        },
        setattribute: function(_e, _f) {
          this.attributes[_e] = _f;
        },
        getattribute: function(_10) {
          return this.attributes[_10];
        },
        addparam: function(_11, _12) {
          this.params[_11] = _12;
        },
        getparams: function() {
          return this.params;
        },
        addvariable: function(_13, _14) {
          this.variables[_13] = _14;
        },
        getvariable: function(_15) {
          return this.variables[_15];
        },
        getvariables: function() {
          return this.variables;
        },
        getvariablepairs: function() {
          var _16 = new array();
          var key;
          var _18 = this.getvariables();
          for(key in _18) {
            _16[_16.length] = key + "=" + _18[key];
          }
          return _16;
        },
        getswfhtml: function() {
          var _19 = "";
          if(navigator.plugins && navigator.mimetypes && navigator.mimetypes.length) {
            if(this.getattribute("doexpressinstall")) {
              this.addvariable("mmplayertype", "plugin");
              this.setattribute("swf", this.xiswfpath);
            }
            _19 = "<embed type=\"application/x-shockwave-flash\" src=\"" + this.getattribute("swf") + "\" width=\"" + this.getattribute("width") + "\" height=\"" + this.getattribute("height") + "\" style=\"" + this.getattribute("style") + "\"";
            _19 += " id=\"" + this.getattribute("id") + "\" name=\"" + this.getattribute("id") + "\" ";
            var _1a = this.getparams();
            for(var key in _1a) {
              _19 += [key] + "=\"" + _1a[key] + "\" ";
            }
            var _1c = this.getvariablepairs().join("&");
            if(_1c.length > 0) {
              _19 += "flashvars=\"" + _1c + "\"";
            }
            _19 += "/>";
          } else {
            if(this.getattribute("doexpressinstall")) {
              this.addvariable("mmplayertype", "activex");
              this.setattribute("swf", this.xiswfpath);
            }
            _19 = "<object id=\"" + this.getattribute("id") + "\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"" + this.getattribute("width") + "\" height=\"" + this.getattribute("height") + "\" style=\"" + this.getattribute("style") + "\">";
            _19 += "<param name=\"movie\" value=\"" + this.getattribute("swf") + "\" />";
            var _1d = this.getparams();
            for(var key in _1d) {
              _19 += "<param name=\"" + key + "\" value=\"" + _1d[key] + "\" />";
            }
            var _1f = this.getvariablepairs().join("&");
            if(_1f.length > 0) {
              _19 += "<param name=\"flashvars\" value=\"" + _1f + "\" />";
            }
            _19 += "</object>";
          }
          return _19;
        },
        write: function(_20) {
          if(this.getattribute("useexpressinstall")) {
            var _21 = new obj.playerversion([6, 0, 65]);
            if(this.installedver.versionisvalid(_21) && !this.installedver.versionisvalid(this.getattribute("version"))) {
              this.setattribute("doexpressinstall", true);
              this.addvariable("mmredirecturl", escape(this.getattribute("xiredirecturl")));
              document.title = document.title.slice(0, 47) + " - flash player installation";
              this.addvariable("mmdoctitle", document.title);
            }
          }
          if( this.getattribute("doexpressinstall") || this.installedver.versionisvalid(this.getattribute("version"))) {
            var n = (typeof _20 == "string") ? document.getelementbyid(_20) : _20;
            n.innerhtml = this.getswfhtml();
            return true;
          } else {
            if(this.getattribute("redirecturl") != "") {
              document.location.replace(this.getattribute("redirecturl"));
            }
          }
          return false;
        }
      };
      obj.playerversion = function(_29) {
        this.major = _29[0] != null ? parseint(_29[0]) : 0;
        this.minor = _29[1] != null ? parseint(_29[1]) : 0;
        this.rev = _29[2] != null ? parseint(_29[2]) : 0;
      };
      obj.swfobjectutil.getplayerversion = function() {
        var _23 = new obj.playerversion([0, 0, 0]);
        if(navigator.plugins && navigator.mimetypes.length) {
          var x = navigator.plugins["shockwave flash"];
          if(x && x.description) {
            _23 = new obj.playerversion(x.description.replace(/([a-za-z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
          }
        } else {
          if(navigator.useragent && navigator.useragent.indexof("windows ce") >= 0) {
            var axo = 1;
            var _26 = 3;
            while(axo) {
              try {
                _26++;
                axo = new activexobject("shockwaveflash.shockwaveflash." + _26);
                _23 = new obj.playerversion([_26, 0, 0]);
              } catch(e) {
                axo = null;
              }
            }
          } else {
            try {
              var axo = new activexobject("shockwaveflash.shockwaveflash.7");
            } catch(e) {
              try {
                var axo = new activexobject("shockwaveflash.shockwaveflash.6");
                _23 = new obj.playerversion([6, 0, 21]);
                axo.allowscriptaccess = "always";
              } catch(e) {
                if(_23.major == 6) {
                  return _23;
                }
              }
              try {
                axo = new activexobject("shockwaveflash.shockwaveflash");
              } catch(e) {}
            }
            if(axo != null) {
              _23 = new obj.playerversion(axo.getvariable("$version").split(" ")[1].split(","));
            }
          }
        }
        return _23;
      };
      //获取浏览器flash版本号
      function getflashversion() {
        var version = obj.swfobjectutil.getplayerversion();
        $("#flash_banben").html(version['major'] + "." + version['minor'] + "." + version['rev']);
      };
      //获取操作系统屏幕分辨率
      function getscreensize() {
        return {
          width: screen.width,
          height: screen.height
        };
      }
      $("#fenbianlv").html(getscreensize().width + "*" + getscreensize().height);
      function getnetline() {
        $('#netline').text("网络已链接");
        window.ononline = function() {
          $('#netline').text("网络已链接");
        };
        window.onoffline = function() {
          $('#netline').text("网络已断开");
        };
      }
      //获取浏览器版本
      function getexplorerversion() {
        var sys = {};
        var ua = navigator.useragent.tolowercase();
        var s;
        var result = "";
        (s = ua.match(/qqbrowser\/([\d.]+)/)) ? sys.qqbrowser = s[1]:
          (s = ua.match(/msie ([\d.]+)/)) ? sys.ie = s[1] :
          (s = ua.match(/(trident)\/([\d.]+)/)) ? sys.ie = '11.0' :
          (s = ua.match(/firefox\/([\d.]+)/)) ? sys.firefox = s[1] :
          (s = ua.match(/chrome\/([\d.]+)/)) ? sys.chrome = s[1] :
          (s = ua.match(/opera.([\d.]+)/)) ? sys.opera = s[1] :
          (s = ua.match(/version\/([\d.]+).*safari/)) ? sys.safari = s[1] : 0;
        if(sys.ie)
          result = "ie " + sys.ie;
        else if(sys.firefox)
          result = "firefox " + sys.firefox;
        else if(sys.chrome)
          result = "chrome " + sys.chrome;
        else if(sys.opera)
          result = "opera " + sys.opera;
        else if(sys.safari)
          result = "safari" + sys.safari;
        else if(sys.qqbrowser)
          result = "qqbrowser" + sys.qqbrowser;
        else
          result = "未知";
        $("#liulanqi").html(result + "(内核)");
      }
      //获取操作系统版本
      function getosversion() {
        var opname = "";
        var name = "";
        var ua = window.navigator.useragent;
        var iswin = (navigator.platform == "win32") || (navigator.platform == "windows") || (navigator.platform == "win64");
        var ismac = (navigator.platform == "mac68k") || (navigator.platform == "macppc") || (navigator.platform == "macintosh") || (navigator.platform == "macintel");
        if(ismac) {
          opname = "mac";
          name = "mac";
        } else if(iswin) {
          var osn = "";
          if(ua.indexof("wow") != -1 || ua.indexof("win64") != -1) {
            osn = "64";
          } else {
            osn = "32";
          }
          var osv = ua.substr(ua.indexof("windows nt ") + 11, 3);
          switch(osv) {
            case "5.0":
              opname = "windows xp2000";
              name = "win2000";
              break;
            case "5.1":
              opname = "windows xp ";
              name = "winxp";
              break;
            case "5.2":
              opname = "windows 2003";
              name = "win2003";
              break;
            case "6.1":
              opname = "windows 7 " + osn + "位";
              name = "win7";
              break;
            case "6.3":
              opname = "windows 8 " + osn + "位";
              name = "win8";
              break;
            default:
              name = "other";
              break;
          }
        } else {
          var isunix = (navigator.platform == "x11") && !iswin && !ismac;
          if(isunix) {
            opname = "unix";
            name = "unix";
          } else {
            var islinux = (string(navigator.platform).indexof("linux") > -1);
            if(islinux) {
              opname = "linux";
              name = "linux";
            } else {
              name = "other";
            }
          }
        }
        $("#xitong").html(opname);
      }
      //获取网速
      function getnet() {
        var starttime = new date();
        var size = 0, //文件长度,由脚本使用head自动计算 
          url = "2017-08-22_233329.jpg?" + new date().valueof(); //获取文件的长度: 
        var xhr = $.ajax({
          type: 'get', //"head",
          url: url,
          success: function(msg) {
            size = xhr.getresponseheader('content-length');
            //开始get数据: 
            $.get(url, function(data) {
              var endtime = new date();
              usetime = endtime - starttime;
              if(usetime == 0) {
                usetime = 10;
              }
              var speed = (size / (1024)) / (usetime / (1000));
              var result_text = speed.tofixed(2);
              $("#wangsu").html(result_text + "kb/s");
            });
          }
        });
      }
      getnet();
      getosversion();
      getexplorerversion();
      getflashversion();
      getnetline();
    }());
  </script>
</html>

总结

以上所述是小编给大家介绍的js代码实现电脑配置检测功能,希望对大家有所帮助