网速测试
类别: ASP教程
代码存为speedtest.asp,同目录下放一个大约100K的img.jpg图片,具体大小请改代码中的var fs = 137.57 //img.jpg文件大小(K)
<HTML>
<HEAD>
<TITLE>网站速度测试</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY>
<%
Response.Expires=-1
Response.ExpiresAbsolute=Now()-1
Response.cachecontrol="no-cache"
Dim Imgrandom
Randomize
Imgrandom = Int(799999 * Rnd + 200000)
%>
<SCRIPT LANGUAGE="JavaScript">
window.status = "下载数据中..."
var st = new Date()
</SCRIPT>
<img src="img.jpg?id=<%=Imgrandom%>" width=0 height=0 onerror = showerr() onload="showspeed();">
<SCRIPT LANGUAGE="JavaScript">
function showspeed()
{
var fs = 137.57 //img.jpg文件大小(K)
var l = 2 //小数点的位数
var et = new Date()
alltime = fs*1000/(et - st)
Lnum = Math.pow(10,l)
calcspeed = Math.round(alltime*Lnum)/Lnum
showtxt.innerHTML = ("服务器时间为:<%=now%>,您在本站的下载速度为:"+calcspeed+" (K/秒)")
window.status = "您在本站的下载速度为:"+calcspeed+" (K/秒)"
}
function showerr()
{
showtxt.innerHTML = ("数据下载错误,请刷新重试")
window.status = "数据下载错误,请刷新重试"
}
</SCRIPT>
<button style="font-size:12px;width:80;height:19px;" onclick=location.href="speedtest.asp?<%=Imgrandom%>">重新测试</button>
<span id=showtxt></span>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>网站速度测试</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY>
<%
Response.Expires=-1
Response.ExpiresAbsolute=Now()-1
Response.cachecontrol="no-cache"
Dim Imgrandom
Randomize
Imgrandom = Int(799999 * Rnd + 200000)
%>
<SCRIPT LANGUAGE="JavaScript">
window.status = "下载数据中..."
var st = new Date()
</SCRIPT>
<img src="img.jpg?id=<%=Imgrandom%>" width=0 height=0 onerror = showerr() onload="showspeed();">
<SCRIPT LANGUAGE="JavaScript">
function showspeed()
{
var fs = 137.57 //img.jpg文件大小(K)
var l = 2 //小数点的位数
var et = new Date()
alltime = fs*1000/(et - st)
Lnum = Math.pow(10,l)
calcspeed = Math.round(alltime*Lnum)/Lnum
showtxt.innerHTML = ("服务器时间为:<%=now%>,您在本站的下载速度为:"+calcspeed+" (K/秒)")
window.status = "您在本站的下载速度为:"+calcspeed+" (K/秒)"
}
function showerr()
{
showtxt.innerHTML = ("数据下载错误,请刷新重试")
window.status = "数据下载错误,请刷新重试"
}
</SCRIPT>
<button style="font-size:12px;width:80;height:19px;" onclick=location.href="speedtest.asp?<%=Imgrandom%>">重新测试</button>
<span id=showtxt></span>
</BODY>
</HTML>
- 上一篇: ASP生成条形码
- 下一篇: 备份与恢复SQL SERVER
-= 资 源 教 程 =-
文 章 搜 索