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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 178 ::
收藏到网摘: 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,进行较正.