当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用js统计用户下载网页所需时间的脚本

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 用js统计用户下载网页所需时间的脚本


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 180 ::
收藏到网摘: n/a

下面的方法是个不错的思路,建议对于js感兴趣的朋友,推荐看 有时候,我们可能根据多台服务器,根据IP计算在南方的用户选择南方的服务器,在北方的选择北方的服务器,但是渐渐发现用IP统计经常出现误差.以前曾想过在客户端用ping的方法看看哪台服务器连接快,但是至少需要用户安装一个插件.现在想想,其实用js似乎也可以解决一部分问题
<script language="javascript">
function getDate()
{
var d = new Date();
var s = d.getUTCSeconds();
var m = d.getUTCMilliseconds();
return s + ":" + m;
}
var d1 = getDate();
function _onload()
{
d2 = getDate();
//计算d2,d1的差值,用xmlhttp传回服务器
alert(d1 + " ---- " + d2);
}
window.onload = _onload;
</script>
根据d2和d1的差值计算每一台服务器和客户端的下载速度,都存在cookie当中,然后再进行比较,选择一个较快的.并且过一定时间就更新一次cookie,进行较正.