我想使用 jQuery 或 JavaScript 计算 WiFi 或 WiFi 信号强度的带宽。我知道我们可以计算服务器端代码的强度,但我想在客户端计算。
问问题
5653 次
1 回答
2
检查这个网站,我认为这将适合 WiFi 连接:
这是加载图像时计算下载速度的示例:
var imageAddr = "http://www.tranquilmusic.ca/images/cats/Cat2.JPG" + "?n=" + Math.random();
var startTime, endTime;
var downloadSize = 5616998;
var download = new Image();
download.onload = function() {
endTime = (new Date()).getTime();
showResults();
}
startTime = (new Date()).getTime();
download.src = imageAddr;
function showResults() {
var duration = (endTime - startTime) / 1000; //Math.round()
var bitsLoaded = downloadSize * 8;
var speedBps = (bitsLoaded / duration).toFixed(2);
var speedKbps = (speedBps / 1024).toFixed(2);
var speedMbps = (speedKbps / 1024).toFixed(2);
alert("Your connection speed is: \n" +
speedBps + " bps\n" +
speedKbps + " kbps\n" +
speedMbps + " Mbps\n");
}
于 2013-04-25T11:38:52.823 回答