computing RTT problem with javascript
<p>I want to measure how long an RTT is to the server...
Here is the problem, when I have the following work it works perfectly:</p>

<pre><code>var start = new Date();
var startTime=start.getMilliseconds();

document.write('&lt;img src="http://mysite.com/myfile.gif" onload="getEndTime()"&gt;');


function getEndTime()
{
    var stop= new Date();
    var t=stop.getMilliseconds()-startTime;
    console.log(t);
 }
</code></pre>

<p>But if i want to store t in a variable and print it out of the function, it most of the time doesn't work! </p>

<p>For example:</p>

<pre><code>var start = new Date();
var startTime=start.getMilliseconds();

document.write('&lt;img src="http://mysite.com/myfile.gif" width="1" height="1" onload="getEndTime()"&gt;');

var rtt;

function getEndTime()
{
    var stop= new Date();
    var t=stop.getMilliseconds()-startTime;
    rtt=t;
}

console.log(rtt);
</code></pre>

<p>rtt will be 0 most of the time!!... Can anyone help? it is so frustrating!....</p>
