-
-
原理:利用img元素的 onload 事件求得img加载的速度既网络速度 asp代码如下 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY> <center>本文来自:http://struts.blog.ccidnet.com/blog-htm-itemid-239706-uid-6587-do-showone-type-blog.html 作 者:jstruts <span id=showtxt> <span id=imgs>
<form action="guide.asp" name="speedform" method="post"><span id="percenttitle"> <input type="hidden" name="avrspeed"> </form> </center> <script language="javascript" type="text/javascript" src="percent.js"> </script>
<img src="img.jpg?id=<%=Imgrandom%>" width=0 height=0 onerror = showerr() οnlοad="showspeed();">
<script language="javascript" type="text/javascript">
window.status = "测速中,请稍候..."
var st = new Date()
var i=0
var totalspeed=0
function showspeed()
{ var number = Math.floor(Math.random()*1000000) +200000;
i++ //循环控制 10次
var fs = 104 //img.jpg文件大小(K)
var l = 2 //小数点的位数
var et = new Date()
alltime = fs*1000/(et - st) time=alltime
Lnum = Math.pow(10,l)
calcspeed = Math.round(alltime*Lnum)/Lnum*8
if(i <11){ totalspeed=totalspeed+calcspeed;
PaintPercent("_PercentBar",10*i, "安装进度",true,20);//进度条显示控制
percenttitle.innerHTML=(10*i+"%");
var imgstr="<img src='img.jpg?id="+number+"' width=0 height=0 onerror = showerr()>";
imgs.innerHTML = (imgstr); st=et; } else{ percenttitle.innerHTML=("测速完毕,转向生成报告...."); document.speedform.avrspeed.value=Math.round(totalspeed/10);//四舍五入结果赋给
speedform.avrspeed window.setTimeout(rendresult,2000);//两秒后提交表单,转向结果页面(结果页面还有其它功能,这里先不详述)。 } }
function rendresult() { speedform.submit(); }
function showerr() { showtxt.innerHTML = ("数据下载错误,请刷新重试")
window.status = "数据下载错误,请刷新重试" } </script> </BODY> </HTML>