js實現簡單網速測試方法

只能測到瞬時速度,不是很準確

<!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="測試圖片" src="http://sp2.yokacdn.com/photos/f3/4f/702018/photo_322092_500.jpg"  οnlοad="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)?0:(speed>50 && speed<=100)?1:(speed>=100 && speed<200)?2:(speed>=200 && speed<300)?3:4;
        alert(scope)
        document.getElementById("showtxt").innerHTML = ("您的下載速度爲:" + arr[scope] + " (K/秒)")  
    }  
</script>
 </body>
</html>


 

發佈了47 篇原創文章 · 獲贊 2 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章