Home > Web Front-end > JS Tutorial > Complete example of js simple network speed test method_javascript skills

Complete example of js simple network speed test method_javascript skills

WBOY
Release: 2016-05-16 15:25:31
Original
2281 people have browsed it

The example in this article describes the js simple network speed test method. Share it with everyone for your reference, the details are as follows:

The screenshot of the running effect is as follows:

The specific code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
 <title> New Document </title>
 <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
 <meta name="Generator" content="EditPlus">
 <meta name="Author" content="xinmingyang">
 <meta name="Keywords" content="">
 <meta name="Description" content="">
 </head>
 <body>
 <SCRIPT language=JavaScript>
   var st = new Date();
</SCRIPT>
<IMG alt="Complete example of js simple network speed test method_javascript skills" src="http://www.jb51.net/images/logo.gif" onload="showspeed();">
<div id='showtxt'></div>
<script>
  var arr=["网速低于50KB","网速在50-100KB之间","网速在100-200KB之间","网速在200-300KB之间","视频通讯"];
  function showspeed() 
  { 
    var filesize =35.4;  //measured in KB  
    var et = new Date(); 
    var speed = Math.round(filesize*1000)/(et - st);
    document.title=speed;
    var scope=(speed>0 && speed<=50)&#63;0:(speed>50 && speed<=100)&#63;1:(speed>=100 && speed<200)&#63;2:(speed>=200 && speed<300)&#63;3:4;
    alert(scope)
    document.getElementById("showtxt").innerHTML = ("您的下载速度为:" + arr[scope] + " (K/秒)") 
  } 
</script>
 </body>
</html>

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template