I am having questions of getting the client connection speed in exclusively Javascript.
I searched online some of them when user clicks a link, then pop up the connection speed.
I do not want to add any html code for getting the speed. Seems after the image finished loading,
the getConnectionSpeed function is still running, and at the mean time, the next assign command
strConnectSpeed = connectionSpeed; is executed, so the strConnectSpeed is always undefined.
I tried to put a while loop saying while (strConnectSpeed=="undefined"); this time the while
loop block everything and slows everything, and the next command afer while does not execute
until the while loop is done. These two cases seem contradictory to me, how to explain this?
Anyone can help me to get the strConnectSpeed assigned with the value?
///////////////////////////////////////////////////////////
<html><head>
</head><BODY>
<script language=javascript>
<!--
var connectionSpeed = 0;
var strConnectSpeed = "undefined";
drawCSImage('email_newsletter.gif',35053 , 'width=1 height=1');
setTimeout("checkSpeed()", 5000);
//the following commands get executed before the setTimeout
//so the strConnectSpeed is always "undefined"
//How can I get strConnectSpeed assigned value and use it?
//I tried while loop, but it slows everything.
strConnectSpeed = connectionSpeed;
alert(strConnectSpeed );
/////////////////////////////////////////////
function drawCSImage( fileLocation, fileSize, imgTagProperties ) {
start = (new Date()).getTime();
document.write('');
return;
}
function getConnectionSpeed( start, fileSize ) {
end = (new Date()).getTime();
return (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
}
function checkSpeed()
{
strConnectSpeed = connectionSpeed;
alert(strConnectSpeed );
}
//--></script>
</body>
</html>
I searched online some of them when user clicks a link, then pop up the connection speed.
I do not want to add any html code for getting the speed. Seems after the image finished loading,
the getConnectionSpeed function is still running, and at the mean time, the next assign command
strConnectSpeed = connectionSpeed; is executed, so the strConnectSpeed is always undefined.
I tried to put a while loop saying while (strConnectSpeed=="undefined"); this time the while
loop block everything and slows everything, and the next command afer while does not execute
until the while loop is done. These two cases seem contradictory to me, how to explain this?
Anyone can help me to get the strConnectSpeed assigned with the value?
///////////////////////////////////////////////////////////
<html><head>
</head><BODY>
<script language=javascript>
<!--
var connectionSpeed = 0;
var strConnectSpeed = "undefined";
drawCSImage('email_newsletter.gif',35053 , 'width=1 height=1');
setTimeout("checkSpeed()", 5000);
//the following commands get executed before the setTimeout
//so the strConnectSpeed is always "undefined"
//How can I get strConnectSpeed assigned value and use it?
//I tried while loop, but it slows everything.
strConnectSpeed = connectionSpeed;
alert(strConnectSpeed );
/////////////////////////////////////////////
function drawCSImage( fileLocation, fileSize, imgTagProperties ) {
start = (new Date()).getTime();
document.write('');
return;
}
function getConnectionSpeed( start, fileSize ) {
end = (new Date()).getTime();
return (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
}
function checkSpeed()
{
strConnectSpeed = connectionSpeed;
alert(strConnectSpeed );
}
//--></script>
</body>
</html>