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


Posted in Javascript onMarch 21, 2018

下面一段代码给大家分享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代码实现电脑配置检测功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
javascript定义函数的方法
Dec 06 Javascript
jquery 操作DOM的基本用法分享
Apr 05 Javascript
node.js中的console.log方法使用说明
Dec 09 Javascript
PHP 数组current和next用法分享
Mar 05 Javascript
12行javascript代码绘制一个八卦图
Apr 02 Javascript
JavaScript地理位置信息API
Jun 11 Javascript
原生JS实现的放大镜效果实例代码
Oct 15 Javascript
微信小程序如何获知用户运行小程序的场景教程
May 17 Javascript
JS伪继承prototype实现方法示例
Jun 20 Javascript
基于vue2.0的活动倒计时组件countdown(附源码下载)
Oct 09 Javascript
Vue项目中使用better-scroll实现一个轮播图自动播放功能
Dec 03 Javascript
layui table 多行删除(id获取)的方法
Sep 12 Javascript
vue2 mint-ui loadmore实现下拉刷新,上拉更多功能
Mar 21 #Javascript
javascript与PHP动态往类中添加方法对比
Mar 21 #Javascript
详解PHP后期静态绑定分析与应用
Mar 21 #Javascript
在 Linux/Unix 中不重启 Vim 而重新加载 .vimrc 文件的流程
Mar 21 #Javascript
用p5.js制作烟花特效的示例代码
Mar 21 #Javascript
AngularJS监听ng-repeat渲染完成的方法
Mar 20 #Javascript
vue对storejs获取的数据进行处理时遇到的几种问题小结
Mar 20 #Javascript
You might like
一个好用的分页函数
2006/11/16 PHP
PHP 获取远程文件大小的3种解决方法
2013/07/11 PHP
PHP自带ZIP压缩、解压缩类ZipArchiv使用指南
2015/03/03 PHP
PHP并发查询MySQL的实例代码
2017/08/09 PHP
Jquery 实现弹出层插件
2015/01/28 Javascript
JavaScript编程中布尔对象的基本使用
2015/10/25 Javascript
JS跨域解决方案之使用CORS实现跨域
2016/04/14 Javascript
JavaScript原生对象常用方法总结(推荐)
2016/05/13 Javascript
JS运动特效之任意值添加运动的方法分析
2018/01/24 Javascript
关于js陀螺仪的理解分析
2019/04/11 Javascript
详解微信小程序调用支付接口支付
2019/04/28 Javascript
vue history 模式打包部署在域名的二级目录的配置指南
2019/07/02 Javascript
微信小程序的开发范式BeautyWe.js入门详解
2019/07/10 Javascript
解决layui中onchange失效以及form动态渲染失效的问题
2019/09/27 Javascript
js 实现watch监听数据变化的代码
2019/10/13 Javascript
electron踩坑之remote of undefined的解决
2020/10/06 Javascript
Python六大开源框架对比
2015/10/19 Python
python目录与文件名操作例子
2016/08/28 Python
解决seaborn在pycharm中绘图不出图的问题
2018/05/24 Python
解析Python3中的Import
2019/10/13 Python
python常用数据重复项处理方法
2019/11/22 Python
Python列表切片常用操作实例解析
2019/12/16 Python
使用Python爬虫库requests发送请求、传递URL参数、定制headers
2020/01/25 Python
Tensorflow 卷积的梯度反向传播过程
2020/02/10 Python
详解Pandas 处理缺失值指令大全
2020/07/30 Python
Python安装Bs4的多种方法
2020/11/28 Python
关于探究python中sys.argv时遇到的问题详解
2021/02/23 Python
纯CSS3实现给头像加个光芒四射且旋转的背景动画效果
2014/05/07 HTML / CSS
Tory Burch英国官方网站:美国时尚生活品牌
2017/12/06 全球购物
Linux Interview Questions For software testers
2013/05/17 面试题
马智宇结婚主持词
2014/04/01 职场文书
优秀团员事迹材料2000字
2014/08/20 职场文书
第二批党的群众路线教育实践活动个人对照检查材料
2014/09/23 职场文书
起诉书范文
2015/05/20 职场文书
Java中Quartz高可用定时任务快速入门
2022/04/03 Java/Android
分析MySQL优化 index merge 后引起的死锁
2022/04/19 MySQL